I want to copy all files in a directory except some files in a specific sub-directory. I have noticed that 'cp' command didn't have a --exclude option. So, how can I achieve this?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
- Null-terminated string, opening file for reading
Expanding on mvds’s comment, this works for me
The easiest way I found, where you can copy all the files excluding files and folders just by adding their names in the parentheses:
Why use
rsync
when you can do:This assumes the target directory structure being the same as the source's.
I use a "do while" loop to read the output of the find command. In this example, I am matching (rather than excluding) certain patterns since there are a more limited number of pattern matches that I want than that I don't want. You could reverse the logic with a -not in front of the -iname flags:
I use the above to copy all music type files that are newer on my server than the files on a Western Digital TV Live Hub that I have mounted at /media/wd. I use the above because I have a lot of DVD files, mpegs, etc. that I want to exclude AND because for some reason rsync looks like it is copying, but after I look at the wd device, the files are not there despite no errors during the rsync with this command:
Just move it temporally into a hidden directory (and rename it after, if wanted).