Saturday, September 24, 2016

find / cpio directory copy / move / archive info

Create a cpio archive:
localhost% find path/ -depth -print | cpio -oaV > archive.cpio
localhost% find path/ -depth -print | cpio -oaV -O archive.cpio
Create a cpio archive and compress it:
localhost% find path/ -depth -print | cpio -oaV | gzip -c > archive.cpio.gz
Extract a compressed cpio archive:
cd to parent directory of location to install.
gzip -cd path-to-cpio-gz | cpio -idmv
<uncompress to stdout>  pipe <cpio install stream from stdin> 
Extract a cpio archive:
localhost% cpio -imVd < archive.cpio
localhost% cpio -imVd -I archive.cpio
List the contents of a cpio archive:
localhost% cpio -it < archive.cpio
localhost% cpio -it -I archive.cpio
Use cpio copy-pass to copy a directory structure to another location:
localhost% find path/ -depth -print | cpio -pamVd /new/parent/dir

cpio over ssh

To cpio a local directory, send the output to ssh and feed it to cpio on a remote host:
localhost% find path/ -depth -print | cpio -oaV | ssh user@host 'cpio -imVd'
Ssh to a remote host, cpio a remote directory, and get its output locally:
localhost% ssh user@host "find path/ -depth -print | cpio -oaV" | cpio -imVd 
Another reference
  1. Change to the appropriate directory.
    # cd filesystem1
  2. 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 from the bottom up.
    Creates a list of files.
    Creates directories as needed.
    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.


No comments:

Post a Comment