The use of Linux common compression, decompression and scp remote transmission commands

1. Compression command

tar -zcvf filename.tar.gz filename
tar -zcvf filename.tgz filename
tar -jcvf filename.tar.bz2 filename
zip filename.zip filename
zip -r location.zip location
gzip -d filename.gz filename
rar -a filename.rar filename

Example: tar -zcvf filename.tar.gz filename
insert image description here

2 Unzip command

tar -xvf filename.tar
tar -zxvf filename.tar.gz
tar -zxvf filename.tgz
tar -jxvf filename.tar.bz2
tar -xZvf filename.tar.Z
unrar e filename.rar 
unrar x filename.rar /mnt/sdb/path 
unzip filename.zip -d filepath

Example: tar -zxvf filename.tar.gz
insert image description here

3. Large files are compressed and split into multiple compressed files

If a file is too large and needs to be split into multiple files of a specified size, it can be compressed into one large file first.

tar -zcvf filename.tar.gz filenam

Then use the split command to cut

split -b 1000M -d -a 1 filename.tar.gz filename.tar.gz.
cat filename.tar.gz | split -b1000M -d -a 1 filename.tar.gz.

Parameter meaning:

  • -b 4000M means to set the size of each split package, the unit can still be k
  • -d "parameter specifies that the suffix of the generated split package is in the form of numbers
  • -ax to set the length of the sequence (the default value is 2), here the length of the sequence is set to 1

one step operation

tar -zcvf filename.tar.gz filename | split -b 4000M -d -a 1 -filename.tar.gz.

The method of decompressing multiple compressed files is as follows

cat filename.tar.gz.* | tar -zxv

4. Remote transmission command scp

4.1 Copy local files to remote host directory

  scp node.tar.gz [email protected]:/home

Copy the current directory file of this machine to the directory of port 22 of the host node.tar.gzthrough the user of the remote host . After executing this command, there will be a prompt:root192.168.0.10/home
insert image description here

Unable to determine the authenticity of host '192.168.0.10'.
ECDSA key fingerprint is SHA256: ***
Are you sure you want to continue connecting (yes/no/)?

Enter yes, and then enter the password of the remote host to display the progress of the transfer

4.2 Copy the local directory to the remote host directory

本机Create a directory scptest, create a file under the directory zqtxt.txt, copy the directory together with the file to the remote host

scp -r scptest [email protected]:/home

insert image description here
192.168.0.10:/home directory
insert image description here

4.3 Copy the files from the remote host to this machine

远程主机Create a file test.txtand copy the file to 本机the /mnt/sdb directory

scp [email protected]:/home/test.txt /mnt/sdb

insert image description here
Local directory:
insert image description here

4.4 Copy the remote host directory to this machine

远程主机Create a directory scpromate, create a file under the directory romate.txt, copy the directory together with the file to the 本机/mnt/sdb directory

scp -r [email protected]:/home/scpromate/ /mnt/sdb

insert image description here
Local directory:
insert image description here

Guess you like

Origin blog.csdn.net/qq_29864051/article/details/130461481