Created
July 5, 2012 04:42
-
-
Save dedy-purwanto/3051434 to your computer and use it in GitHub Desktop.
Bash: Copy files with list of excluded files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Say you need to copy files in a folder to somewhere else, except that you have a list of files that might be exist in the source folder but you don't want them to be copied. Your text file that has this list is named list.txt: | |
------------------------ | |
exclude1.mp3 | |
dont_copy.mpeg | |
nyancat.jpg | |
------------------------ | |
$ cd source/ | |
$ cat /path/to/list.txt | tr '\n' '#' | sed 's/.$//g' | sed 's/#/\\\\|/g' | xargs -i sh -c "ls | grep -v '{}'" | xargs -i cp -v -u {} /path/to/dest/ | |
This will copy all files in the source/ except those files in the list.txt, if the file is already exist in the /past/to/dest/, it will be ignored (-u). | |
It's simply printing the list.txt, changing all line breaks to #, and remove the trailing #, and then change # to a regex of OR (\|), and do `ls` and inverse grep with the list of excluded files, and copy the non-excluded files to /path/to/dest. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment