English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Linux cpio command is used for file backup.
cpio is a tool program used to create and restore backup files, which can add and extract files from cpio or tar backup archives.
cpio [-0aABckLovV][-C <Input/OutputSize>][-F <BackupFile>][-H <BackupFormat>][-O <BackupFile>][--block-size=<BlockSize>][--force-local][--help][--quiet][--version] or cpio [-bBcdfikmnrsStuvV][-C <Input/OutputSize>][-E <TemplateFile>][-F <BackupFile>][-H <BackupFormat>][-I <BackupFile>][-M <ReturnInformation>][-R <Owner><:/.><Group>][--block-size=<BlockSize>][--force-local][--help][--no-absolute-filenames][--no-preserve-owner][--only-verify-crc][--quiet][--sparse][--version][TemplateStyle...] or cpio [-0adkiLmpuvV][-R <Owner><:/.><Group>][--help][--no-preserve-owner][--quiet][--sparse][--version][PurposePurpose]
parameter:
Create backup files
[[email protected] var]# ll //Display files in the current directory Total usage 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 4month 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 5month 8 15:25 lock drwxr-xr-x 14 root root 4096 5month 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 5month 8 15:14 run drwxr-xr-x 16 root root 4096 2008-03-30 spool drwxrwxrwt 3 root root 4096 1month 13 18:53 tmp drwx------ 2 root root 4096 2004-07-08 tux drwxr-xr-x 8 root root 4096 1month 19 19:39 www drwxr-xr-x 3 root root 4096 2008-03-30 yp [[email protected] var]# ls | cpio -o >123.cpio //Create backup files 25 blocks [[email protected] var]# ll //Display files in the current directory Total usage 172 -rw-r--r-- 1 root root 1024 5month 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 4month 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 5month 8 15:25 lock drwxr-xr-x 14 root root 4096 5month 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 5month 8 15:14 run drwxr-xr-x 16 root root 4096 2008-03-30 spool drwxrwxrwt 3 root root 4096 1month 13 18:53 tmp drwx------ 2 root root 4096 2004-07-08 tux drwxr-xr-x 8 root root 4096 1month 19 19:39 www drwxr-xr-x 3 root root 4096 2008-03-30 yp [[email protected] var]#
Unpack backup files
[[email protected] var]# ls | cpio -i -l 123.cpio
Unpack backup files 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 unpacking
[[email protected] var]# cpio -i -u -I 123.cpio
Reverse match during unpacking, specify files not to unpack
[[email protected] var]# cpio -i -I 123.cpio -f *.c //Do not unpack 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 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 complete input 3 block [[email protected] test]#
Copy file
[[email protected] test]# cpio -p /root a.c //User input b.c c.c //Press Ctrl+D complete input 3 block