Home > Article > Operation and Maintenance > What are the Linux backup file commands?
Recommended tutorial: "linux video tutorial"
What are the Linux backup file commands?
Linux backup file commands are:
1.tar (compression and decompression)
-c: Create a compressed archive
-x: Decompress
-t: View the contents
-r: Append files to the end of the compressed archive
-u: Update File
in the original compressed package. These five are independent commands. One of them must be used for compression and decompression. It can be used in conjunction with other commands but only one of them can be used.
The following parameters are optional when compressing or decompressing files as needed.
-z: With gzip attribute
-j: With bz2 attribute
-Z: With compress attribute
-v: Show all Process
-O: Extract the file to standard output
The following parameter -f is required
-f: Use the file name. Remember, this parameter is the last A parameter that can only be followed by the file name.
# tar -cf all.tar *.jpg
This command is to package all .jpg files into a package named all.tar. -c means generating a new package, and -f specifies the file name of the package.
# tar -rf all.tar *.gif
This command is to add all .gif files to the all.tar package. -r means adding files.
# tar -uf all.tar logo.gif
This command is to update the logo.gif file in the original tar package all.tar. -u means to update the file.
# tar -tf all.tar
This command is to list all the files in the all.tar package. -t means to list the files.
# tar -xf all.tar
This command is to extract all the files in the all.tar package. -t means unzip
Compression
tar -cvf jpg.tar *.jpg
//Package all jpg files in the directory into tar.jpg
tar -czf jpg.tar.gz *.jpg
//Package all jpg files in the directory into jpg.tar, compress them with gzip, and name them For jpg.tar.gz
tar -cjf jpg.tar.bz2 *.jpg //
Package all jpg files in the directory into jpg.tar, and compress them with bzip2 , named jpg.tar.bz2
tar -cZf jpg.tar.Z *.jpg//
After packaging all the jpg files in the directory into jpg.tar, and use compress compression, named jpg.tar.Z
rar a jpg.rar *.jpg
//Rar format compression, you need to download rar for linux first
zip jpg.zip *.jpg
//Zip format compression, you need to download zip for linux first
Unzip
tar -xvf file.tar
//Decompress tar package
tar -xzvf file.tar.gz
//Decompress tar.gz
tar -xjvf file .tar.bz2
//Extract tar.bz2
tar -xZvf file.tar.Z
//Extract tar.Z
unrar e file.rar
//Unzip rar
unzip file.zip
//Unzip zip
Summary
1. *.tar Use tar -xvf Decompress
2, *.gz Use gzip -d or gunzip to decompress
3, *.tar.gz and *.tgz Use tar -xzf to decompress
4 , *.bz2 uses bzip2 -d or bunzip2 to decompress
5, *.tar.bz2 uses tar -xjf to decompress
6, *.Z uses uncompress to decompress
7. *.tar.Z Use tar -xZf to decompress
8. *.rar Use unrar e to decompress
9. *.zip Use unzip to decompress
Example: Compression A directory
tar -cvf compressed package name Project name
tar -cvf AppStore_180808.tar AppStore
Example: Decompress a tar package
tar -xvf compressed package name
tar -xvf AppStore_180808.tar
##2.cp (copy)
cp Copy files or directoriesSyntaxcp [Options] Source file target fileCommon options:-a: Equivalent to pdr -d: Copy the link file. The target file is also the link file or directory pointing to the source file link. -i: When the target file already exists, you will be asked whether to overwrite it. -p: Copy together with the attributes of the file. Commonly used for backup -r: recursive copy, used to copy directories -s: copied as a symbolic link file, that is, a shortcut, the link file is deleted, and the symbolic link file becomes invalid. -l: Create a hard link link file instead of copying the file itself. The source file is deleted, but the target file remains. Source file: Single file or directory, use the r option to copy the directory. Multiple files or directories. When there are multiple files or directories, the target file must be an existing directory. Note: When ordinary users use cp under a non-privileged user root, they need to pay attention to whether the parent directory of the source file has rx permissions. Whether the file has r permission. When a general user uses option -a, the permission time attribute can be copied, but the user and group attributes cannot be copied. Example:Backup test1 file with root permissioncp -a test1 ./beifen
cp -pdf The file to be backed up and the file after backup
Linux system tutorial》
The above is the detailed content of What are the Linux backup file commands?. For more information, please follow other related articles on the PHP Chinese website!