Tar command
command function to compress and decompress files
command format tar[necessary parameters [select parameters] [file]
Tar Packaging tools
-F # #指定生成包的名字, it is recommended that-F be written separately as a parameter --delete filename # #删除包中指定文件 --get filename # #取出包中指定文件 Note: -C-T-X cannot appear on the same string of command lines
tar -cf etc.tar /etc ##生成归档包tar -f etc.tar --get file tar -f etc.tar --delete filetar -rf etc.tar file ##添加文件到打包文件中
The necessary parameters are as follows:
-A add compressed file to existing compression
-B Set Chunk size
-C Create a new compressed file
-D Record File differences
-R Add a file to a file that has been compressed
-u add changed and existing files to a compressed file that already exists
-P retain original file attributes
-X extracting files from compressed files
-T displays the contents of the compressed file
-Z Support gzip unzip files
-j Support bzip2 Extract files
-Z Support Compress unzip files
-V Show Operation procedure
-L File System boundary settings
-K Keep the original file without overwriting
-m reserved files are not overwritten
-W confirm the correctness of the compressed file
The optional parameters are as follows:
-B Set Number of blocks
-c switch to the specified directory
-f Specifies the compressed file
Help Display Help information
–version displaying version information
Common options
-CVF Pack all the files into a. Tar package
Example to package log.log into Log.tar
Command TAR-CVF Log.tar log.log
-ZCVF package all files and compress them into. tar.gz Package (gzip compressed)
Example to package log.log into log.tar.gz
Command TAR-ZCVF Log.tar log.log
-JCVF package all files and compress them into. TAR.BZ2 packages (compressed with bzip2)
Example to package log.log into log.tar.bz2
Command TAR-JCVF log.tar.bz2 log.log
-ZTVF review. What files are in the tar.gz package?
Instance lookup what files are in log.tar.gz
Command TAR-ZTVF log.tar.gz
-ZXVF. tar.gz Decompression
Instance decompression log.tar.gz to the current directory (you can change the decompression location via the CD command)
Command TAR-ZXVF opt/soft/test/log.tar.gz
Instance has selective decompression of test1.log in file log.tar.gz
Command tar zxvf opt/soft/test/log.tar.gz test1.log
-P retains the properties of the original file (including last modified time, permissions, etc.)
The instance is packaged under the current directory (/TMP/TEST2) Log1.log Log2.log Log3.log to log.tar.gz and unzip it to the/tmp/test1 folder
Command 1 tar zcvpf log.tar.gz log1.log log2.log log3.log
Command 2 Cd/tmp/test1
Command 3 tar zxvpf/tmp/test2/log.tar.gz
Command 4 ll (view the extracted file information and find the same file attributes before and after decompression)
-n Specifies a date that is newer than a date backup
Instance compresses test to log.tar.gz, dated older than 2016/12/7 days
Command Tar-n "2016/12/7"-ZCVF log.tar.gz test
–exclude Exclude some files
The instance will back up all the files under SCF, except for files under Scf/service
Command Tar–exclude SCF/SERVICE/ZCVF scf.tar.gz scf/*
gzip command
The command function uses a wide range of compression programs, and the compressed file suffix is. gz
command format gzip[parameter [file or directory]
Common options
-A or –ASCII use ASCII text mode.
-C or –stdout or –to-stdout the compressed file output to the standard output device, not to change the original file.
-D or –decompress or--uncompress unpack the compressed file.
Instance extracts all the files in the current directory
Command GZIP-DV *
-F or –force forcibly compress the file. Ignores the existence of a file name or a hard connection and whether the file is a symbolic connection.
-L or –list lists information about the compressed file.
Instance gets the information of all the compressed files in the current directory
Command Gzip-l *
The original file name and time stamp are not saved when the file is compressed by-N or –no-name.
-N or –name compress the file, save the original file name and time stamp.
-Q or –quiet does not display a warning message.
-R or –recursive recursively handles all files and subdirectories under the specified directory.
Instance compresses a tar backup file
Command Gzip-r Log.tar
Compressed directory with instance recursion
Command GZIP-RV TEST6
Extract directory for instance recursion
Command GZIP-DV TEST6
-s< compress the tail string > or--suffix< compress the tail string > change the compressed Word tail string.
-T or –test tests whether the compressed file is correct.
-V or –verbose shows the instruction execution process.
-V or –version displays version information.
-num adjusts the speed of compression with the specified number num,-1 or –fast represents the fastest compression method (low compression ratio), 9 or –best represents the slowest compression method (high compression ratio). System default value is 6
Gzip Xxxx.tar =====> xxxx.tar.gz # #压缩gunzip xxxx.tar.gz =====> Xxxx.tar # #解压tar ZCVF xxxx.tar.gz destination file # #打包压缩文件tar ZXVF xxxx.tar.gz # # #xxxx. tar.gz===>xxxx
BZ2 (highest compression ratio)
bzip2 Xxxx.tar =====> xxxx.tar.bz2 # #压缩bunzip2 xxxx.tar.bz2 =====> xxxx.tar # #解压tar JCVF xxxx.tar.bz2 Target file # #打包压缩文件tar JXVF xxxx.tar.bz2 # # #xxxx. tar.bz2===>xxxx
XZ (//Slow)
XZ Xxxx.tar =====> xxxx.tar.xz # #压缩unxz xxxx.tar.xz =====> xxxx.tar # #解压tar JCVF xxxx.tar.xz destination file # #打包压缩文件tar JXVF xxxx.tar.xz # # #xxxx. tar.xz===>xxxx
The first three files can be compressed directly in one step
Zip (//with Win-compatible, folder must be archived before it can be compressed) zip-r xxx.tar.zip xxx.tar # # #压缩unzip xxx.tar.zip # # #解压
Remote file replication shared SCP remote replication
SCP file [email protected]:/directory # #上传文件scp-R dir [email protected]:/directory # # Long passing directory SCP [email protected]:/filename /direcotry # #下载文件scp-R [email protected]:/directory /direcotry # #下载目录
Rsync remote Synchronization (synchronization is reflected in the synchronization of permissions information, etc.)
(If the contents of the folder are added/indicated after the directory is not included in the folder) rsync file|direcotry [email protected]:/directory (remote send) rsync [email protected]:/ Directory/directory (remote copy) parameter options:- R # #同步目录 (do not add this parameter will skip the directory directly, only copy ordinary files ) -L # #不忽略链接 (default ignore link)- p # #不忽略权限- T # #不忽略时间戳- G # #不忽略组信息- o # #不忽略用户信息 -D # #不忽略设备文件 (Files beginning with permission C b)
Example one: Package all the files in the/etc directory into/tmp/etc.tar
[[email protected] ~]# TAR-CVF/TMP/ETC.TAR/ETC <== package only, do not compress!
[[email protected] ~]# tar-zcvf/tmp/etc.tar.gz/etc <== packaged, compressed with gzip
[[email protected] ~]# tar-jcvf/tmp/etc.tar.bz2/etc <== packaged, bzip2 compressed
#特别注意, the file name after the parameter F is taken by itself, we used to use. Tar as an identification.
#如果加z参数, the. tar.gz or. tgz represent the gzip compressed tar file~
#如果加j参数, use. tar.bz2 as the file name.
#上述指令在执行的时候, a warning message is displayed:
# "tar:removing leading '/' from member names" That's a special setting for absolute paths.
Example two: Check out what files are in the above/tmp/etc.tar.gz file?
[Email protected] ~]# tar-ztvf/tmp/etc.tar.gz
#由於我们使用gzip压缩, so when you check the file in the tar file,
#就得要加上z这个参数了! It's important!
Example three: Extracting the/tmp/etc.tar.gz file under/USR/LOCAL/SRC
[Email protected] ~]# CD/USR/LOCAL/SRC
[Email protected] src]# tar-zxvf/tmp/etc.tar.gz
#在预设的情况下, we can untie the zip file anywhere! In the case of this example,
#我先将工作目录变换到/usr/local/src under, and Untie/tmp/etc.tar.gz,
#则解开的目录会在/usr/local/src/etc! Also, if you enter/USR/LOCAL/SRC/ETC
#则会发现, the file attributes in this directory may be different from/etc/.
Example four: under/tmp, I just want to untie the etc/passwd inside the/tmp/etc.tar.gz.
[Email protected] ~]# cd/tmp
[Email protected] tmp]# tar-zxvf/tmp/etc.tar.gz etc/passwd
#我可以透过tar-ZTVF to check the file name within the Tarfile, if only one file,
#就可以透过这个方式来下达! Notice that! The root directory within the etc.tar.gz/is taken away!
Example five: Back up all the files in the/etc/and save their permissions!
[Email protected] ~]# tar-zxvpf/tmp/etc.tar.gz/etc
#这个-P properties are important, especially if you want to preserve the properties of the original file!
Example six: In/home, more than 2005/06/01 new files are backed up
[Email protected] ~]# tar-n ' 2005/06/01 '-ZCVF home.tar.gz/home
Example seven: I want to back up/home, etc, but don't/home/dmtsai
[Email protected] ~]# tar--EXCLUDE/HOME/DMTSAI-ZCVF myfile.tar.gz/home/*/etc
Example eight: Unpack the/etc/directly under/TMP without generating files!
[Email protected] ~]# cd/tmp
[Email protected] tmp]# TAR-CVF-etc | TAR-XVF-
#这个动作有点像是cp-R/etc/tmp ~ still has its use!
#要注意的地方在於输出档变成-and the input file becomes-and another | exists ~
#这分别代表standard output, standard input and Pipeline command!
TAR-CVF Log.tar Log2012.log Package only, do not compress!
TAR-ZCVF log.tar.gz log2012.log After packing, compress with gzip
TAR-ZCVF log.tar.bz2 Log2012.log is packaged to bzip2 compression
The file name after the parameter F is taken by itself, and we are accustomed to using. Tar as an identification. If the z parameter is added, a. tar.gz or. tgz is used to represent the gzip compressed tar package, or the. tar.bz2 as the TAR package name if the J parameter is added.
. BZ
Decompression 1:bzip2-d filename.bz
Decompression 2:BUNZIP2 filename.bz
Compression: Unknown
. tar.bz
Decompression: Tar jxvf FileName.tar.bz
Compression: Unknown
. Z
Decompression: uncompress filename.z
Compression: Compress FileName
. Tar. Z
Decompression: Tar zxvf filename.tar.z
Compression: Tar zcvf filename.tar.z DirName
. zip
Decompression: Unzip Filename.zip
Compression: Zip Filename.zip DirName
. rar
Decompression: rar x Filename.rar
Compression: rar a Filename.rar DirName
Example 2: Check which files are in the tar package above
Command: TAR-ZTVF log.tar.gz
Example 5: Files are backed up and their permissions are saved
Command: TAR-ZCVPF log31.tar.gz log2014.log log2015.log log2016.log
Example 6: In a folder, a new file is backed up than a date
Command: Tar-n "2012/11/13"-ZCVF log17.tar.gz test
Example 7: Backup folder contents are excluded from some files
Command: Tar--exclude scf/service-zcvf scf.tar.gz scf/*
Use SecureCRT to upload and download files
When you use SSH to manage Linux servers, you often need to interact with files remotely and locally. The upload and download function directly with SECURECRT is the most convenient, and SECURECRT file Transfer Protocol has ASCII, Xmodem, Zmodem.
File Transfer Protocol:
File transfer is the main form of data exchange. In the case of file transfer, in order for the file to be correctly identified and transmitted, we need to establish a unified transport protocol between the two computers. This protocol includes the identification of documents, the starting and ending time of transmission, the judgment and correction of errors, etc. The common transport protocols are as follows:
ASCII: This is the fastest transport protocol, but only text files can be transferred.
Xmodem: This ancient transmission protocol is slow, but due to the use of CRC error detection method, the transmission accuracy rate can be as high as 99.6%.
Ymodem: This is an improved version of Xmodem, using 1024-bit segments to deliver faster than Xmodem
Zmodem:zmodem adopts the stream-flow (streaming) transmission mode, the transmission speed is fast, but also has the function of automatically changing the section size and the breakpoint continuation transmission, the fast error detection and so on. This is currently the most popular file transfer protocol.
In addition to the above several, there are Imodem, Jmodem, Bimodem, Kermit, lynx and other agreements, because there is no majority of manufacturers support, here is omitted to say.
SECURECRT can use Linux under the Zmodem protocol to quickly transfer files, the use of very convenient. Specific steps:
A Before uploading a download using SECURECRT, you need to install Lrzsz to the server:
1. Download lrzsz-0.12.20.tar.gz from the address below
Http://down1.chinaunix.net/distfiles/lrzsz-0.12.20.tar.gz
2. Check the install documentation inside for instructions and details on installation parameters.
3. Unzip the file
Tar zxvf lrzsz-0.12.20.tar.gz
4. Enter the catalogue
CD lrzsz-0.12.20
5,./configure--prefix=/usr/local/lrzsz
6. Make
7. Make Install
8. Establish a soft link
#cd/usr/bin
#ln-S/usr/local/lrzsz/bin/lrz RZ
#ln-S/usr/local/lrzsz/bin/lsz sz
9. Testing
Run RZ pop-up securecrt upload window and use SecureCRT to upload and download files.
Two Set the default directory for SECURECRT uploads and downloads.
Options->session Options->terminal->xmodem/zmodem
Directory settings for uploading and downloading in the right column directory
Three Using Zmodem to upload files from a client to a Linux server
1. Log in to the Linux terminal with SECURECRT.
2. Select the path where you want to place the uploaded file, in the directory and then enter the RZ command, SECURECRT will pop up the file selection dialog box, find the file you want to upload in the search scope, press the Add button. Then OK can upload the file to Linux.
Or, in the Transfer->zmodem upoad list pop-up File selection dialog box, select the file and press the Add button. Then the OK window closes automatically. Then under Linux, select the directory where the files are stored and enter the RZ command. Liunx the file to the directory.
Four To download files to the client using Zmodem:
SZ filename
Zmodem receive can start on its own. The downloaded file is stored in the default download directory you set.
Rz,sz is a command-line tool that Linux/unix Zmodem file transfer with Windows, the Windows side needs to support Zmodem TELNET/SSH client, SECURECRT can log in SecureCRT to unix/ Linux host (telnet or SSH) O Run command RZ, that is, to receive files, SECURECRT will pop up the file selection dialog box, select the file and close the dialog box, the file will be uploaded to the current directory O run the command sz File1 File2 is to send files to Windows (the saved directory can be configured) more convenient than the FTP command, and the server does not have to open the FTP service
Linux (6/17)--file package upload and download