Linux system management and maintenance - cpio command

  

Function description: cpio command is to redirect the file by redirecting the file, restore the recovery tool, it can be decompressed with ".cpio" or "<quo;.tar" The ending file.

Use format: cpio [options] > file name or device name cpio [options] < file name or device name option description: detailed option description see the table below

option meaning-o Package a copy of the file into a file or output the file to the device. -i Extract the packaged files or restore the backups on the device to the system. -t View the contents of the files packaged by cpio or the contents of the files output to the device. -v Displays the file name during the packaging process. -d Automatically create the corresponding directory during cpio restore file. -c A newer way of storing. -B allows the default Blocks to be increased to 5120 bytes and the default Blocks to 512 bytes. This has the advantage of speeding up access.

Example: 1. Back up all the normal files under /etc to /opt/etc.cpio, using the following command: [root@mylinux ~]# find /etc –type f |  Cpio –ocvB >/opt/etc.cpio2. Back up all the data on the system to the tape drive, use the following command: [root@mylinux ~]# find /-print |  Cpio -covB > /dev/st0# The "/dev/st0&rdquo" is the device name of the tape, which represents the SCSI tape drive. 3. To view the files backed up on the tape drive, use the following command: # Sometimes it may be because there are too many files backed up, and one screen cannot be displayed. At this time, we use the following command to output the file information of the tape drive to the file. [root@mylinux ~]# cpio -icdvt < /dev/st0 > /tmp/st_content4. Restore the backup package in Example 1 to the appropriate location. If there is the same file to overwrite, use the following command:

[root@mylinux ~]#cpio –icduv < /opt/etc.cpio# Note that the path of cpio recovery, if cpio uses absolute path when packaging backup, then it will automatically restore to these absolute paths when recovering. In this case, all backup files will be restored to the corresponding /etc path. In the catalog. Similarly, if a backup path is used for a backup, the restore will also return to the relative path. Through the above example, it can be seen that cpio can not directly read the file, it needs the full path name of each file or directory to recognize the read, and the output of the find command just does this, so the cpio command is generally and find The command is used together. In fact, the above example we have seen their combined usage.

Copyright © Windows knowledge All Rights Reserved