Easy Tutorial
❮ Linux Comm Restore Linux Comm Mc ❯

Linux cpio Command

Linux Command Manual

The Linux cpio command is used for backing up files.

cpio is a tool for creating and restoring backup archives. It can add to, extract from, or list the contents of cpio or tar backup archives.

Syntax

cpio [-0aABckLovV][-C &lt;input/output size>][-F &lt;backup file>][-H &lt;backup format>][-O &lt;backup file>][--block-size=&lt;block size>][--force-local][--help][--quiet][--version] or cpio [-bBcdfikmnrsStuvV][-C &lt;input/output size>][-E &lt;pattern file>][-F &lt;backup file>][-H &lt;backup format>][-I &lt;backup file>][-M &lt;return message>][-R <owner><:/.><group>][--block-size=&lt;block size>][--force-local][--help][--no-absolute-filenames][--no-preserve-owner][--only-verify-crc][--quiet][--sparse][--version][pattern...] or cpio [-0adkiLmpuvV][-R <owner><:/.><group>][--help][--no-preserve-owner][--quiet][--sparse][--version][destination directory]

Parameters:

Example

Creating a backup file

[[email protected] var]# ll // Display files in the current directory
total 164
drwxr-xr-x  2 root  root  4096 2008-03-30 account
drwxr-xr-x  9 root  root  4096 2008-03-30 cache
drwxr-xr-x  3 netdump netdump 4096 2008-03-30 crash
drwxr-xr-x  3 root  root  4096 2008-03-30 db
drwxr-xr-x  3 root  root  4096 2008-03-30 empty
drwxr-xr-x  3 root  root  4096 2008-03-30 ftp
drwxrwx--T  2 root  gdm   4096 4月 9 20:17 gdm
drwxr-xr-x 25 root  root  4096 2008-03-30 lib
drwxr-xr-x  2 root  root  4096 2004-08-13 local
drwxrwxr-x  6 root  lock  4096 5月 8 15:25 lock
drwxr-xr-x 14 root  root  4096 5月 8 15:14 log
lrwxrwxrwx  1 root  root   10 2008-03-30 mail -> spool/mail
drwxr-xr-x  2 root  root  4096 2004-08-13 nis
drwxr-xr-x  2 root  root  4096 2004-08-13 opt
drwxr-xr-x  2 root  root  4096 2004-08-13 preserve
drwxr-xr-x 16 root  root  4096 5月 8 15:14 run
drwxr-xr-x 16 root  root  4096 2008-03-30 spool
drwxrwxrwt  3 root  root  4096 1月 13 18:53 tmp
drwx------  2 root  root  4096 2004-07-08 tux
drwxr-xr-x  8 root  root  4096 1月 19 19:39 www
drwxr-xr-x  3 root  root  4096 2008-03-30 yp
[[email protected] var]# ls | cpio -o >123.cpio // Create a backup file
25 blocks
[[email protected] var]# ll // Display files in the current directory
total 172
-rw-r--r--  1 root  root  1024 5月 24 13:06 123.cpio
drwxr-xr-x  2 root  root  4096 2008-03-30 account
drwxr-xr-x  9 root  root  4096 2008-03-30 cache
drwxr-xr-x  3 netdump netdump 4096 2008-03-30 crash
drwxr-xr-x  3 root  root  4096 2008-03-30 db
drwxr-xr-x  3 root  root  4096 2008-03-30 empty
drwxr-xr-x  3 root  root  4096 2008-03-30 ftp
drwxrwx--T  2 root  gdm   4096 4月 9 20:17 gdm

drwxr-xr-x 25 root root 4096 2008-03-30 lib drwxr-xr-x 2 root root 4096 2004-08-13 local drwxrwxr-x 6 root lock 4096 May 8 15:25 lock drwxr-xr-x 14 root root 4096 May 8 15:14 log lrwxrwxrwx 1 root root 10 2008-03-30 mail -> spool/mail drwxr-xr-x 2 root root 4096 2004-08-13 nis drwxr-xr-x 2 root root 4096 2004-08-13 opt drwxr-xr-x 2 root root 4096 2004-08-13 preserve drwxr-xr-x 16 root root 4096 May 8 15:14 run drwxr-xr-x 16 root root 4096 2008-03-30 spool drwxrwxrwt 3 root root 4096 Jan 13 18:53 tmp drwx------ 2 root root 4096 2004-07-08 tux drwxr-xr-x 8 root root 4096 Jan 19 19:39 www drwxr-xr-x 3 root root 4096 2008-03-30 yp [[email protected] var]#


Extract backup file

[[email protected] var]# ls | cpio -i -l 123.cpio


Extract backup file and list detailed information

[[email protected] var]# cpio -t -I 123.cpio 123.cpio a.c b.c c.c ……omitted part of the result


Force extraction

[[email protected] var]# cpio -i -u -I 123.cpio


Extract with reverse matching, specifying files not to extract

[[email protected] var]# cpio -i -I 123.cpio -f *.c

//Do not extract files ending with .c


Add files to the specified .cpio file

[[email protected] var]# ls 123.cpio crash ftp local mail preserve tmp yp account db gdm lock nis run tux cache empty lib log opt spool www [[email protected] var]# cpio -o -O 123.cpio -A db //user input, press Ctrl+D to end input 1 block [[email protected] var]#


Backup files from standard input

[[email protected] test]# ls a. a.c b.c c.c d.c f.c [[email protected] test]# cpio -o >123.cpio a.c //user input b.c c.c //press Ctrl+D to complete input 3 block [[email protected] test]#


Copy files

[[email protected] test]# cpio -p /root a.c //user input b.c c.c //press Ctrl+D to complete input 3 block ```

Linux Command Manual

❮ Linux Comm Restore Linux Comm Mc ❯