First, whether locally or remotely, if you need to move or copy more files and are not too large, with the CP command and MV command less efficient, you can use the Tar tool to be copied/moved content to package/compress, and then copy/move, and finally unpack/decompress.
In addition, it is also a key technique that you do not have to copy after the tar packaging/compression, unpack/decompress, you can package/compress the other side through the pipeline to perform copy unpack/decompress.
For example, the TAR command can be combined with an 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 the A machine/tmp/test/to the corresponding directory in the B machine, where the tar CF-/tmp/test/|nc B ' IP 5555 transfers the content side by 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 to the local port of 555 and unpack the received content to the specified directory (---c parameter specifies the target directory)
In addition, tar can be combined with SCP, SSH commands:
After the A machine is packaged, copy to B machine and unpack
TAR-CF-/tmp/test | SSH B ' IP ' cd/tmp; TAR-XF-"
Pack in a machine and copy the packaged files to the B machine
TAR-CF-/tmp/test | SSH B ' IP ' cd/tmp; Cat-> Test.tar "
TAR-CF-/tmp/test | Scp-b ' User@b ' ip:/tmp
Copy the packing files of a machine to B machine and unpack
Zcat Test.tar | SSH B ' IP ' cd/tmp; TAR-XF-"
It can also be used directly locally:
Cd/tmp/test1
TAR-CF-. | (Cd/tmp/test2; TAR-XVPF-)
But someone tried to conclude that local direct use of CP faster
Some other tips:
Copying a single file in addition to copying the directory, sometimes with the file/directory properties to copy together. You can copy the directory recursively using the-R parameter in the CP command, using the-P argument to copy the file retention attributes (by default: Mode,ownership,timestamps can also pass--preserve[=attr_list] Specifies attributes to be specifically reserved, such as context, links,xattr, and all, to copy files using the-D parameter to retain 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, write a simple little script:
The code is as follows:
Cd/tmp/test
For i in *
Todo
CP $i Target Directory
echo $i is ok ....
Done
Finally, add a tip that is not a skill: before using a tool to accomplish a task, think about the tools that are most appropriate for your current tool? Are there any better tools or methods? If the tool does work well for the current task, are there any special techniques to improve productivity when using the tool? (Typically, you can see the help document as a bonus).