cpio command is used to process archive files (for example, *.cpio or
*.tar files).
cpio stands for “copy in, copy out”.
cpio performs the following three operations.
¦Copying files to an archive
¦Extracting files from an
archive
¦Passing files to another
directory tree
cpio takes the list of files from the standard input while creating an
archive, and sends the output to the standard output.
1. Create *.cpio Archive File
You can create a *.cpio archive that contains files and directories
using cpio -ov
[root@server1~]# cd objects
[root@server1~]# ls
file1.o file2.o file3.o
[root@server1~]# ls | cpio -ov > /tmp/object.cpio
-o (copy out) cpio -o reads
the standard input to obtain a list of path names and copies those files onto
the standard output.
-v Verbose. Print a list of
file names. When used with the -t option, the table of contents looks like the output
of ls -l command.
As seen above, the ls command passes the three object filenames to cpio
command and cpio generates the object.cpio archive.
2. Extract *.cpio Archive File
cpio extract: To extract a given *.cpio file, use cpio -iv as shown
below.
[root@server1~]# mkdir output
[root@server1~]# cd output
[root@server1 output]# cpio -idv < /tmp/object.cpio
-i (copy in) cpio -i extracts files from the standard input.
-d Creates directories as needed
-v Verbose. Print a list of file names. When used with the -t
option, the table of contents looks like the output of ls -l command.
3. Create *.cpio Archive with Selected Files
The following example creates a *.cpio archive only with *.c files.
[root@server1~]# find . -iname *.c -print | cpio -ov
>/tmp/c_files.cpio
-o (copy out) cpio -o reads
the standard input to obtain a list of path names and copies those files onto
the standard output.
-v Verbose. Print a list of
file names. When used with the -t option, the table of contents looks like the output
of ls -l command.
4. Create *.tar Archive File using cpio -F
We already know how to use the tar command effectively.
Did you know that you can also use cpio command to create tar files as
shown below?
[root@server1~]# ls | cpio -ov -H tar -F sample.tar
-o (copy out) cpio -o reads
the standard input to obtain a list of path names and copies those files onto
the standard output.
-v Verbose. Print a list of
file names. When used with the -t option, the table of contents looks like the output
of ls -l command.
-H (header) Read or write header information in header format.
Always use this option or the -c option
when the origin and the
destination machines are different types (mutually exclusive with -c and -6).
-F Archive filename to use instead of standard input or output.
As seen above, instead of redirecting the standard output you can
mention the output archive filename with the option -F.
5. Extract *.tar Archive File using cpio command
You can also extract a tar file using cpio command as shown below.
[root@server1~]# cpio -idv -F sample.tar
-i (copy in) cpio -i extracts files from the standard input.
-d Creates directories as needed
-v Verbose. Print a list of file names. When used with the -t
option, the table of contents looks like the output of ls -l command.
-F Archive filename to use instead of standard input or output.
6. View the content of *.tar Archive File
To view the content of *.tar file, do the following.
[root@server1~]# cpio -it -F sample.tar
-i (copy in) cpio -i extracts files from the standard input.
-t Print a table of contents of the input. No files are created
(mutually exclusive with -V).
-F Archive filename to use instead of standard input or output.
7. Create a *.cpio Archive with the Original files that a Symbolic Link
Points
cpio archive can be created with the original files that a symbolic link
is referring to as shown below.
[root@server1~]# ls | cpio -oLv >/tmp/test.cpio
-o (copy out) cpio -o reads
the standard input to obtain a list of path names and copies those files onto
the standard output.
-L Follow symbolic links. The default is not to follow symbolic
links.
-v Verbose. Print a list of file names. When used with the -t
option, the table of contents looks like the output of ls -l command.
8. Preserve the File Modification Time while restoring *.cpio
The modification time of the files can be preserved when we are
restoring the cpio archive files as shown below.
[root@server1~]# ls | cpio -omv >/tmp/test.cpio
-o (copy out) cpio -o reads
the standard input to obtain a list of path names and copies those files onto
the standard output.
-m Retain previous file
modification time. This option is ineffective on directories that are being
copied (mutually exclusive with -a).
-v Verbose. Print a list of
file names. When used with the -t option, the table of contents looks like the output
of an ls -l command.
To know about the courses CLICK HERE..!!
Contact US CLICK HERE..!!
To know about the courses CLICK HERE..!!
Contact US CLICK HERE..!!
ReplyDeleteHi there, awesome site. I thought the topics you posted on were very interesting. I tried to add your RSS to my feed reader and it a few. take a look at it, hopefully I can add you and follow.
Corporate Training in Chennai
Thanks for sharing this information You may also refer http://www.s4techno.com/linux-administration-training-online/ for more information…
ReplyDelete"Nice post. You just post the right content i was searcing for. Good Job. Linux Courses in India | Linux Server Training Institute in India training company SSDN Technologies, and become a well versed software professional.
ReplyDelete"