[Linux Command Explanation Encyclopedia] 043. Detailed explanation of the usage and common options of the cpio command in Linux

cpio

A utility program for creating and restoring backup files

Supplementary Note

cpioCommands are mainly tools used to create or restore backup files. cpioCommands can copy files to or from an archive.

grammar

cpio [选项]

options

  • -0Or --null: accept new column control characters, usually used with the parameter findof the command -print0;
  • -aOr --rest-access-time: reset the access time of the file;
  • -AOr --append: Append to an existing backup file, and this backup file must be stored on the disk, not in the tape drive;
  • -bOr --awap: the effect of this parameter -ssis the same as specifying the parameter at the same time;
  • -B: Change the input/output block size to 5210Bytes;
  • -c: use old ASCII backup format;
  • -C <区块大小>Or --io-size=<区块大小>: set the input/output block size, the unit is Byte;
  • -dOr --make-directories: if necessary, cpiocreate a directory by yourself;
  • -E <范本文件>Or --pattern-file=<范本文件>: specify a template file, which contains one or more template styles, let cpiountie the files that meet the template conditions, and the format is one template style per column;
  • -f <备份档>Or --file=<备份档>: Specify the name of the backup file to replace the standard input or output, and also use another host's storage device to access the backup file through the network;
  • -H <备份格式>: Specify the file format to be used for backup;
  • -iOr --extract: Execute the copy-in mode to restore the backup file;
  • -l <备份档>: Specifies the name of the backup file, which is used to replace the standard input, and can also be used to read the backup file through the network using the storage device of another host;
  • -k: This parameter will be ignored and not processed, and is only responsible for solving cpiocompatibility issues between different versions;
  • -lOr --link: replace the copy file with a hard link, which can be used in copy-pass mode;
  • -LOr --dereference: directly copy the original file pointed to by the link without establishing a symbolic link;
  • -mOr preserve-modification-time: do not change the change time of the file;
  • -M <回传信息>Or --message=<回传信息>: set the information for replacing the storage medium;
  • -nOr --numeric-uid-gid: When using -tvthe parameter to list the content of the backup file, if the parameter is added -n, the file list will be listed with the user ID and group ID instead of the owner and group name;
  • -oOr --create: Execute the copy-out mode to create a backup file;
  • -O <备份档>: Specify the name of the backup file, which is used to replace the standard output, and can also use the storage device of another host to store the backup file through the network;
  • -pOr --pass-through: Execute the copy-pass mode, skip the backup step, and directly copy the file to the destination directory;
  • -rOr --rename: use interactive mode when there is a file name that needs to be changed;
  • -R <拥有者><:/.><所属群组>Or ----owner<拥有者><:/.><所属群组>: When restoring backup files in copy-in mode, or copying files in copy-pass mode, you can specify the owner and group of the copied files for these backups;
  • -sor --swap-bytes: exchange the contents of each queue of bytes;
  • -Sor --swap-halfwords: swap the contents of each nibble;
  • -tOr --list: display the input content;
  • -uOr --unconditional: replace all files, regardless of whether the date and time are old or new, and directly overwrite without asking;
  • -vOr --verbose: display the execution process of the command in detail;
  • -VOr --dot: when executing the command, add .a sign in front of the execution program of each file;
  • --block-size=<区块大小>: Set the input/output block size, if the value is set to 5, the block size is 2500, if it is set to 10, the block size is 5120, and so on;
  • --force-local: Force the backup file to be stored on the local host;
  • --help: online help;
  • --no-absolute-filenames: Create a file name using a relative path;
  • --no-preserve-owner: The owner of the file is not kept, whoever unlocks the backup file will own those files;
  • --only-verify-crc: When the backup file adopts CRC backup format, this parameter can be used to check whether each file in the backup file is correct;
  • --quiet: Do not display how many blocks have been copied;
  • --sparse: If a file contains a large number of consecutive 0 bytes, save the file as a sparse file;
  • --version: Display version information.

example

To /etcback up all common files under /opt/etc.cpio, use the following command:

find /etc -type f | cpio -ocvB >/opt/etc.cpio

To back up all data on the system to a tape drive, use the following command:

find / -print | cpio -covB > /dev/st0

where /dev/st0is the device name of the tape, representing a SCSI tape drive.

To view the files backed up on the tape drive in the above example, use the following command:

cpio -icdvt < /dev/st0 > /tmp/st_content

Sometimes because there are too many backup files, one screen cannot be displayed completely. At this time, we use the following command to output the file information of the tape drive to the file.

Restore the backup package in Example 1 to the corresponding location. If the same file is overwritten, use the following command:

cpio -icduv < /opt/etc.cpio

Note that cpioif the recovery path cpiois an absolute path when packaging the backup, it will be automatically restored to these absolute paths during recovery. In this example, all backup files will be restored to the /etccorresponding directory under the path. Similarly, if a relative path is used for the package backup, it will also be restored to the relative path when restoring.

From the above example, it can be seen that cpiothe file cannot be read directly, it needs the full path name of each file or directory to identify and read, and the findoutput of the command just does this, so cpiothe command is generally findused in conjunction with the command. In fact, we have seen their combined usage in the above example.

Learn from scratchpython

[Learn python from zero] 92. Use Python's requests library to send HTTP requests and process responses
[Learn python from zero] 91. Use decorators and dictionaries to manage simple web applications for request paths
[Learn python from zero] 93. Use dictionary management Request path
[Learn python from zero] 89. Use WSGI to build a simple and efficient web server
[Learn python from zero] 88. Detailed explanation of WSGI interface: realize simple and efficient web development
[Learn python from zero] 87. Manually build HTTP server Python Implementation and multi-threaded concurrent processing
[learning python from zero] 86. In-depth understanding of HTTP protocol and its role in browser and server communication
[learning python from zero] 85. Parallel computing technology application of Python process pool
[learning python from zero ] 84. In-depth understanding of threads and processes
[learning python from zero] 83. Python multi-process programming and the use of process pools
[learning python from zero] 82. Realization of chat programs based on multi-threading
[learning python from zero] 81. Python and more Application of thread communication and queue
[learning python from zero] 80. Thread access to global variables and thread safety issues
[learning python from zero] 79. Thread access to global variables and thread security issues
[learning python from zero] 78. File download cases
[ Learning python from zero] 77. TCP server programming and precautions
[learning python from zero] 76. Server and client: key components of network communication
[learning python from zero] 75. TCP protocol: reliable connection-oriented transmission layer communication protocol
[Learn python from zero] 74. UDP network program: detailed explanation of port problems and binding information
[Learn python from zero] 73. UDP network program - send data
[Learn python from zero] 72. In-depth understanding of Socket communication and socket creation The method of
[learning python from zero] 71. Network ports and their functions
[learning python from zero] 70. Network communication methods and their applications: from direct communication to routers to connect multiple networks
[learning python from zero] 69. Network communication and IP address classification analysis
[learning python from zero] 68. Greedy and non-greedy modes in Python regular expressions
[learning python from zero] 67. re module in Python: regular replacement and advanced matching technology
[learning python from zero] 66 .In-depth understanding of regular expressions: a powerful tool for pattern matching and text processing
[Learn python from zero] 65. Detailed explanation of Python regular expression modifiers and their applications
[Learn python from zero] 64. The re.compile method in Python regular expressions Detailed explanation
[learning python from zero] 63. Introduction to the re.Match class in regular expressions and its attributes and methods
[learning python from zero] 62. Python regular expressions: a powerful string matching tool
[learning python from zero] 61. Detailed explanation and application examples of property attributes in Python
[learning python from zero] 60. Exploration generator: a flexible tool for iteration
[learning python from zero] 59. Iterator: an efficient tool for optimizing data traversal
[learning python from zero] 58. Custom exceptions in Python and methods of raising exceptions
[Learn python from zero] 57. Use the with keyword in Python to correctly close resources
[Learn python from zero] 56. The importance and application of exception handling in programming
[Learn python from zero] 55. Serialization and processing in Python Deserialization, application of JSON and pickle modules
[learning python from zero] 54. Writing data in memory
[learning python from zero] 53. CSV files and Python CSV modules
[learning python from zero] 52. Reading and writing files - Python file operation guide
[learning python from zero] 51. Opening and closing of files and its application in Python
[learning python from zero] 49. Object-related built-in functions in Python and their usage
[learning python from zero] 48 .Detailed explanation of inheritance and multiple inheritance in Python
[learning python from zero] 47. The concept and basic use of inheritance in object-oriented programming
[learning python from zero] 46. __new__ and __init__ method analysis and singleton in Python Design patterns
[learning python from zero] 45. Class methods and static methods in Python
[learning python from zero] 44. Private attributes and methods in object-oriented programming
[learning python from zero] 43. Examples in Python object-oriented programming Attributes and class attributes
[Learn python from zero] 42. Built-in attributes and methods in Python
[Learn python from zero] 41. Python magic method (2)
[Learn python from zero] 40. Python magic method (1)
[Learn python from zero] 39. Object-oriented basic grammar and application examples
[Learn python from zero] 38. Use and import of Python packages
[Learn python from zero] 37. Use and precautions of Python custom modules
[From zero Learning python] 36. Methods and skills of using pip in Python for third-party package management
[learning python from zero] 35. Python common system modules and their usage
[learning python from zero] 34. Detailed explanation of the import and use of Python modules
[ Learn python from zero] 33. The role of decorators (2)
[Learn python from zero] 32. The role of decorators (1)
[Learn python from zero] 31. In-depth understanding of higher-order functions and closures in Python
[from Zero learning python] 30. In-depth understanding of recursive functions and anonymous functions
[learning python from zero] 29. "Detailed explanation of function parameters" - understand the different usages of Python function parameters
[learning python from zero] 28. Local variables and globals in Python Variables
[Learn python from zero] 27. Use and nested calls of Python functions
[Learn python from zero] 25. Functions: a tool to improve code writing efficiency
[Learn python from zero] 24. String operations and traversal methods in Python
[Learn python from zero] 23. How to use and common operations of sets (set) in Python
[Learn python from zero] 22. Addition, deletion, modification and query of dictionaries in Python and variables of dictionaries
[Learn python from zero] 21. In Python tuples and dictionaries for
[Learn python from zero] 20. Python list operation skills and examples
[Learn python from zero] 19. Application of looping through lists and list nesting
[Learn python from zero] 18. Detailed explanation of basic operations of Python lists (1)
[From Zero learning python] 17. Format method of Python string (2)
[Learn python from zero] 16. Format method of Python string (1)
[Learn python from zero] 15. In-depth understanding of string and character set encoding
[from Zero learning python] 14. Common operations of Python strings (2)
[Learn python from zero] 13. Common operations of Python strings (1)
[Learn python from zero] 12. Python string operations and applications
[Learn python from zero] 11.Python loop statement and control flow
[learn python from zero] 10. Detailed explanation of Python conditional statement and if nesting
[learn python from zero] 09. Conditional judgment statement in Python
[learn python from zero] 08. Python understands bit operations Operators, operator priority
[learn python from zero] 07. Detailed explanation of Python operators: assignment, comparison and logical operators
[learn python from zero] 06. Use arithmetic operators in Python for calculation and string concatenation
[learn from zero python] 05. Output and input in Python
[learn python from zero] 04. Basics of Python programming: variables, data types and identifiers
[learn python from zero] 03. Python interactive programming and detailed annotations
[Learn python from zero] 02. Introduction to development tools
[Learn python from zero] 01. Install and configure python

Guess you like

Origin blog.csdn.net/qq_33681891/article/details/132616964
Recommended