System Administration Guide, Volume 1

How to Copy Directories Between File Systems (cpio)

  1. Become superuser.

  2. Change to the appropriate directory.

    # cd filesystem1
  3. Copy the directory tree from filesystem1 to filesystem2 by using a combination of the find and cpio commands.

    # find . -print -depth | cpio -pdm filesystem2

    Starts in the current working directory. 


    Prints the file names. 


    Descends the directory hierarchy and prints file names on the way back up. 


    Creates a list of files. 


    Creates directories as needed. 


    Sets the correct modification times on directories. 

    The files from the directory name you specify are copied and symbolic links are preserved.

    You might also specify the -u option. This option forces an unconditional copy. Otherwise older files do not replace newer files. This might be useful if you want an exact copy of a directory, and some of the files being copied might already exist in the target directory.

  4. Verify the copy was successful by displaying the destination directory contents.

    # cd filesystem2
    # ls
  5. If appropriate, remove the source directory.

    # rm -rf filesystem1

Example--Copying Directories Between File Systems (cpio)

# cd /data1
# find . -print -depth | cpio -pdm /data2
19013 blocks
# cd /data2
# ls
# rm -rf /data1

See cpio(1) for more information.