In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Linux system how to copy files, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
First of all, when many files need to be moved or copied locally or remotely and are not too large, it is inefficient to use the cp command and mv command. You can first use the tar tool to package / compress the content to be copied / moved, then copy / move, and finally unpack / decompress.
In addition, it is also a key technique, that is, you do not have to copy and unpack / decompress the tar after it has been packaged / compressed, you can perform copy / unpacking / decompression on one side of the pipeline.
For example, the tar command can be combined with the nc command to quickly transfer files and directories between two machines:
Machine B:
Nc-l 5555 | tar-C / tmp/test/-xf-
A machine:
Tar cf-/ tmp/test/ | nc B'IP 5555
The above steps copy the contents under machine A / tmp/test/ to the corresponding directory of machine B, where tar cf-/ tmp/test/ | nc B'IP 5555 transfers the content through pipes and nc commands to machine B via the corresponding IP address and port 5555, nc-l 5555 | tar-C / tmp/test/-xf-listens on port 555 of the machine. And unpack the received content to the specified directory (the-C parameter specifies the target directory)
In addition, tar can be combined with scp and ssh commands:
After packing in machine A, copy it to machine B and unpack it.
Tar-cf-/ tmp/test | ssh B'IP "cd / tmp; tar-xf -"
Pack in machine An 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'USER@B'IP:/tmp
Copy the packing file of machine A to machine B and unpack it.
Zcat test.tar | ssh B'IP "cd / tmp; tar-xf -"
You can also use it directly locally:
Cd / tmp/test1
Tar-cf -. | (cd / tmp/test2; tar-xvpf -)
However, some people have come to the conclusion that it is faster to use cp directly locally.
Some other tips:
When copying, a directory is copied in addition to a single file, sometimes along with the attributes of the file / directory. You can use the-R parameter to recursively copy the directory in the cp command, the-p parameter to copy the file retention attributes (by default: mode,ownership,timestamps can also specify the attributes to be specially retained through-- preserve [= ATTR_LIST], such as: context, links,xattr, all), and use the-d parameter to copy the file 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, you can write a simple script:
The code is as follows:
Cd / tmp/test
For i in *
Do
Cp $I destination directory
Echo $I is ok....
Done
After reading the above, have you mastered the method of how to copy files in Linux system? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.