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--
This article is about how to use CP / SCP / RSYNC to exclude specific directories from Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
In this article, we will demonstrate how to exclude specific files or directories, or copy using the three most commonly used and widely used utilities for this purpose, namely rsync,cp and scp. Use the cp command to exclude replication of specific files / directories:
Consider the following situation, in which there are five directories in my current working directory.
[root@linuxnix tmp] # ls-ld dir* drwxr-xr-x 2 root root 6 Aug 29 22:47 dir1 drwxr-xr-x 2 root root 71 Aug 29 22:47 dir2 drwxr-xr-x 2 root root 6 Aug 29 22:47 dir3 drwxr-xr-x 2 root root 6 Aug 29 22:47 dir4 drwxr-xr-x 2 root root 6 Aug 29 22:47 dir5
I want to copy the contents of all directories starting with the name dir, except the dir2 directory, and then I can do the following:
[root@linuxnix tmp] # cp-r `ls-A | grep dir | grep-v "dir2" `/ tmp/sahil/
This will copy all dir directories except dir2. If we need to copy all directories and skip a single directory, we can run the following command.
[root@linuxnix tmp] # cp-r! (dir2) / sahil
Except for the directory dir2, all directories and subdirectories in the current working directory will be copied to / sahil. Similarly, if we want to copy all but one file from the current working directory, type
[root@linuxnix dir2] # cp-r! (file3) / sahil
In the above example, all files in the current working directory are copied to / sahil, except for the file named file3.
Use the scp command to exclude specific files / directories from being copied:
The data exclusion mechanism in scp is similar to that previously demonstrated with the cp command. The following is an example. The above command copies all the files from the current working directory, except for the one named file4.
[root@linuxnix dir2] # scp-rp! (file4) 192.168.19.142:/sahil file1 100% 0.0KB/s 00:00 file2 100% 0.0KB/s 00:00 file3 100% 0.0KB/s 00:00 file5 100% 0.0KB/s 00:00 [root@linuxnix dir2] #
Use the rsync command to exclude replication of specific files / directories:
In the command set used to copy files, the most flexible is the rsync command. In this article, we limit our discussion to the ability to exclude certain files / directories from being copied. To copy a file or folder using the rysnc command, use the-exclude flag, as shown in the following example.
[root@linuxnix tmp] # rsync-av-- progress-- exclude= "dir2" dir* / sahil sending incremental file list dir1/ dir3/ dir4/ dir5/ sent 82 bytes received 28 bytes 220.00 bytes/sec total size is 0 speedup is [root@linuxnix tmp] # cd / sahil/ [root@linuxnix sahil] # ls-l total 0 drwxr-xr-x 2 root root 6 Aug 29 22:47 dir1 drwxr-xr-x 2 root root 6 Aug 29 22:47 dir3 drwxr-xr-x 2 root root 6 Aug 29 22:47 dir4 drwxr-xr-x 2 root root 6 Aug 29 22:47 dir5 [root@linuxnix sahil] #
We can also use the-exclude flag when copying files remotely. The following is an example:
[root@linuxnix tmp] # rsync-av-progress-exclude= "dir2" dir* 192.168.19.142:/sahil sending incremental file list dir1/ dir3/ dir4/ dir5/ sent 82 bytes received 28 bytes 220.00 bytes/sec total size is 0 speedup is 0.00 [root@linuxnix tmp] # Thank you for reading! This is the end of this article on "how to use CP / SCP / RSYNC to exclude specific directories in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.