Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

System Administration Guide: Devices and File Systems
Previous Next

Copying Directories Between File Systems (cpio Command)

You can use the cpio (copy in and out) command to copy individual files, groups of files, or complete file systems. This section describes how to use the cpio command to copy complete file systems.

The cpio command is an archiving program that copies a list of files into a single, large output file. This command inserts headers between the individual files to facilitate recovery. You can use the cpio command to copy complete file systems to another slice, another system, or to a media device, such as a tape or diskette.

Because the cpio command recognizes end-of-media and prompts you to insert another volume, it is the most effective command, other than ufsdump, to use to create archives that require multiple tapes or diskettes.

With the cpio command, you frequently use the ls and find commands to list and select the files you want to copy, and then to pipe the output to the cpio command.

How to Copy Directories Between File Systems (cpio)

  1. Become superuser or assume an equivalent role.
  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.

    -print

    Prints the file names.

    -depth

    Descends the directory hierarchy and prints file names from the bottom up.

    -p

    Creates a list of files.

    -d

    Creates directories as needed.

    -m

    Sets the correct modification times on directories.

    For more information, see cpio(1).

    The files from the directory name you specify are copied. The 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 option 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 that the copy was successful by displaying the contents of the destination directory.
    # cd filesystem2
    # ls
  5. If appropriate, remove the source directory.
    # rm -rf filesystem1
Example 29-3 Copying Directories Between File Systems (cpio)
# cd /data1
# find . -print -depth | cpio -pdm /data2
19013 blocks
# cd /data2
# ls
# rm -rf /data1
Previous Next

 
 
  Published under the terms fo the Public Documentation License Version 1.01. Design by Interspire