Frequent copying/moving of a large number of files from remote or local servers is required in daily work. When you encounter a file comparison is more slow, so you want to have a faster way. After collecting, sorting, verifying, there are probably the following kinds.
First, whether local or remote, need to move or copy more files and not too large, with the CP command and the MV command is inefficient, you can first use the Tar tool to copy/move the content will be copied/compressed, then copy/move, and then unpack/unzip.
In addition, it is also a key trick, that is, do not have to copy after the tar packaging/compression, unpacking/decompression, can be packaged/compressed on the other side of the pipeline to perform the copy unpacking/decompression.
For example, the TAR command can be combined with the NC command to quickly transfer files and directories between two machines:
B Machine:
Nc-l 5555 |tar-c/tmp/test/-xf-
A machine:
Tar CF-/tmp/test/|nc B ' IP 5555
The above steps copy the contents of a machine/tmp/test/to the corresponding directory of the B machine, where tar CF-/tmp/test/|nc B ' IP 5555 transfers the content edge packaging edge through the pipeline and NC command to the B machine by the corresponding IP address and 5555 Port, nc-l 5555 |tar-c/tmp/test/-xf-listens on the 555 port of this machine and unpack the received content to the specified directory (the-c parameter specifies the destination directory)
In addition, tar can be combined with SCP and SSH commands:
After package A, copy to Machine B and unpack
TAR-CF-/tmp/test | SSH B ' IP ' cd/tmp; TAR-XF-"
Package on a machine and copy the packaged files to machine B
TAR-CF-/tmp/test | SSH B ' IP ' cd/tmp; Cat-> Test.tar "
TAR-CF-/tmp/test | Scp-b ' [email protected] ' ip:/tmp
Copy the package files from machine A to machine B and unpack
Zcat Test.tar | SSH B ' IP ' cd/tmp; TAR-XF-"
You can also use this directly locally:
Cd/tmp/test1
TAR-CF-. | (Cd/tmp/test2; TAR-XVPF-)
But someone tried to come to the conclusion that local direct with CP faster
Some other tips:
Copying a single file in addition to copying it will also copy the directory, sometimes with the attributes of the file/directory together. You can use the-r parameter in the CP command to recursively copy the directory and copy the file retention property using the-p parameter (by default: Mode,ownership,timestamps can also be used by--preserve[=attr_list] Specify the attributes to be specially reserved such as: Context, links,xattr, all), and use the-D parameter to copy the file to preserve the connection. Or simply use the-a parameter (equivalent to using-DR--preserve=all)
If you want to see the progress of copying a large number of small files, you can write a simple little script:
Cd/tmp/test
For i in *
Do
CP $i Target Directory
echo $i is ok ....
Done
The last tip is to add a technique that is not a trick: think about the tools that are currently being used before using a tool to accomplish a task? Is there a better tool or method? If the tool does work well for the current task, are there any special tricks to improve productivity when using the tool? (Typically, viewing help documents can be harvested unexpectedly.)