English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux cpio command

Linux Command大全

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.

Syntax

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:

  • -0 or--null  Accepts control characters for new columns, usually combined with the "find" command's "-print0 parameter usage.
  • -a or--reset-access-time Reset the file's access time.
  • -A or--append Append to the existing backup file, and this backup file must be stored on the disk and cannot be placed in a tape drive.
  • -b or--swap The effect of this parameter is the same as specifying"-sS" parameter is the same.
  • -B Swap the input/The output block size is changed to5210 Bytes.
  • -c Use the old ASCII backup format.
  • -C<Block Size> or--io-size=<block size>  Set input/The output block size, unit is Byte.
  • -d or--make-directories If necessary, cpio will create directories automatically.
  • -E<Pattern File> or--pattern-file=<Pattern File> Specify the pattern file containing one or more pattern styles so that cpio can extract files that match the pattern, with each line containing one pattern style.
  • -f or--nonmatching Let cpio extract all files that do not match the pattern.
  • -F<Backup File> or--file=<Backup File> Specify the name of the backup file to replace the standard input or output, and also use it to access the backup file on another host's storage device over the network.
  • -H<Backup Format> Specify the file format to be used for backup.
  • -i or--Extract execute copy-In mode, restores the backup file.
  • -l<Backup File> Specify the name of the backup file to replace the standard input, and also use it to read the backup file on another host's storage device over the network.
  • -k This parameter will be ignored and is only responsible for solving compatibility issues between different versions of cpio.
  • -l or--Link Replace the copied file with a hard link, which can be used in copy-Pass mode is used.
  • -L or--Dereference Do not create a symbolic link, directly copy the original file pointed to by the link.
  • -m or preserve-Modification-time Do not change the file's modification time.
  • -M<Return Information> or--message=<Return Information> Set the information of replacing the storage medium.
  • -n or--numeric-uid-gid Use "-When the "tv" parameter lists the contents of the backup file, if the parameter "-n" will list the file list with the user ID and group ID instead of the owner and group name.
  • -o or--Create execute copy-Out mode, creates a backup file.
  • -O<Backup File> Specify the name of the backup file to replace the standard output, and also use it to store the backup file on another host's storage device over the network.
  • -p or--Pass-Through execute copy-Pass mode, skips the backup steps and directly copies the files to the destination directory.
  • -r or--rename  When a file name needs to be changed, use interactive mode.
  • -R<owner><:/.><group> or
  • ----owner<owner><:/.><group>  In copy-In mode restore backup files, or copy-In pass mode, when copying files, you can specify these backups, the owner and group of the copied files.
  • -s or--swap-bytes  Swap the content of every pair of bytes.
  • -S or--swap-halfwords  Swap the content of every half-byte.
  • -t or--list  Display the input content.
  • -u or--unconditional  Replace all files, regardless of the date and time, without asking and directly overwrite.
  • -v or--verbose  Display detailed information about the execution process of the command.
  • -V or--dot  Add a "." prefix to the executable program before executing the command.
  • --block-size=<block size>  Set input/Output block size, if the value is set to5Then the block size is2500, if set to10Then the block size is5120, and so on.
  • --force-local  Force the backup file to be stored on the local host.
  • --help  Online help.
  • --no-absolute-filenames  Use relative paths to establish file names.
  • --no-preserve-owner  Do not retain the file owner, the files belong to the person who opens the backup file.
  • -only-verify-crc  When the backup file uses CRC backup format, this parameter can be used to check whether each file in the backup file is correct and error-free.
  • --quiet  Do not display how many blocks were copied.
  • --sparse  If a file contains a large number of consecutive 0 bytes, then this file is stored as a sparse file.
  • --version  Display version information.

Online examples

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

Linux Command大全