Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the common command cpio in Linux

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about how to use the common command cpio in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Linux commonly used commands cpio commands are used to back up files. Cpio is a tool program used to establish and restore backup files. It can join and unlock files in cpio or tar backup files.

Syntax cpio [- 0aABckLovV] [- F] [- H] [- O] [--block-size=] [--force-local] [--help] [--quiet] [--version] or cpio [- bBcdfikmnrsStuvV] [- C] [- E] [- F] [- H] [- I] [- M] [- R] [--block-size=] [--force-local] [--help] [--no-absolute-filenames] [--no- Preserve-owner] [--only-verify-crc] [--quiet] [--sparse] [--version] [template style.] Or cpio [- 0adkiLmpuvV] [- R] [--help] [--no-preserve-owner] [--quiet] [--sparse] [--version] [destination] parameters:

-0 or-null accepts new column control characters, usually in conjunction with the "- print0" parameter of the find directive.

-an or-reset-access-time resets the access time of the file.

-An or-append is attached to an existing backup file, and the backup file must be stored on disk, not on the tape drive.

-b or-swap this parameter has the same effect as specifying the "- sS" parameter at the same time.

-B changes the input / output block size to 5210 Bytes.

-c uses the old ASCII backup format.

-C or-io-size= sets the input / output chunk size in Byte.

-d or-make-directories cpio will set up its own directory if necessary.

-E or-pattern-file= specifies a template file that contains one or more template styles and allows cpio to unlock files that meet the template criteria in the format of one template style per column.

-f or-nonmatching asks cpio to unlock all files that do not meet the criteria of the template.

-F or-file= specifies the name of the backup file, which is used instead of standard input or output, and allows you to access the backup file over the network using another host's storage device.

-H specifies the file format to be used when backing up.

-I or-extract executes copy-in mode to restore the backup file.

-l specifies the name of the backup file, which is used instead of standard input, so that the backup file can be read over the network using another host's saving device.

-k this parameter is ignored and not processed, and is only responsible for solving the compatibility problem between different versions of cpio.

-l or-link replace copying files with hard connections and can be used in copy-pass mode.

-L or-dereference do not establish a symbolic connection, but directly copy the original file that the connection points to.

-m or preserve-modification-time does not change the change time of the file.

-M or-message= settings change the information about the saved media.

When-n or-numeric-uid-gid uses the "- tv" parameter to list the contents of the backup file, if the parameter "- n" is added, the list of files will be listed with the user identification code and group identification code instead of the owner and group name.

-o or-create executes copy-out mode to establish a backup file.

-O specifies the name of the backup file, which is used instead of standard output, so that the backup file can be stored on another host's storage device over the network.

-p or-pass-through executes copy-pass mode, skipping the backup step and copying files directly to the destination directory.

-r or-rename use interactive mode when there are file names that need to be changed.

-R or

-- when owner restores backup files in copy-in mode, or when copying files in copy-pass mode, you can specify these backups, the owner and group to which the copied files belong.

-s or-swap-bytes exchanges the contents of each pair of bytes.

-S or-swap-halfwords exchanges the contents of each half byte.

Either-t or-list renders the input.

-u or-unconditional replaces all files, regardless of whether the date and time is old or new, without inquiry.

-v or-verbose shows the execution of the instruction in detail.

When-V or-dot executes instructions, add "." before the executor of each file. Number

-block-size= sets the input / output block size. If the value is set to 5, the block size is 2500, if set to 10, the block size is 5120, and so on.

-force-local forces backup files to be stored on the local host.

-help online help.

-no-absolute-filenames uses a relative path to establish the file name.

-no-preserve-owner does not retain the owner of the file. Whoever unlocks the backup file will own those files.

-only-verify-crc when the backup file is in CRC backup format, you can use this parameter to check whether each file in the backup file is correct.

-quiet does not show how many chunks have been copied.

-sparse if a file contains a large number of consecutive 0 bytes, save the file as a sparse file.

-version displays version information.

For example, backup the etc directory

$find. / etc-print | cpio-ov > etc.cpio when the file is to be recovered

# cpio-idv only views the etc.cpio file, and you can use the

After # cpio-tv is imported, the output is as follows:

Drwxrwxr-x 4 quiethea quiethea 0 Nov 4 17:14 etc-rw-rw-r-- 1 quiethea quiethea 0 Nov 4 17:07 etc/2 drwxrwxr-x 2 quiethea quiethea 0 Nov 4 17:07 etc/11-rw-rw-r-- 1 quiethea quiethea 0 Nov 4 17:07 etc/11/11-rw-rw-r-- 1 quiethea quiethea 0 Nov 4 17:07 etc/4 drwxrwxr-x 2 quiethea quiethea 0 Nov 4 17:07 etc/22-rw-rw-r-- 1 quiethea quiethea 0 Nov 4 17:07 etc/3-rw-rw-r-- 1 quiethea quiethea 0 Nov 4 17:07 etc/1-rw-rw-r-- 1 quiethea quiethea 0 Nov 4 17:07 etc/5 shows the name of the file to be restored.

Now, when the kernel starts up, it will hang an initrd memory file system in advance, and this initrd file system image can be made by cpio. See the kernel source documentation initrd.txt.

For example, I have a very simple file system rootfs, which can be mirrored as follows

$cd rootfs $find. | cpio-c-o-v | gzip-9-n >.. / ramdisk.img. In this way, a ramdisk.img compressed file system image is generated under the parent directory.

Command to decompress the image and restore it to a file system

$mkdir rootfs $cp ramdisk.img rootfs $cd rootfs $mv ramdisk.img ramdisk.img.gz $gunzip ramdisk.img.gz $cpio-I so that the contents of the original rootfs are in the current directory.

Thank you for reading! This is the end of the article on "how to use cpio in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report