how to copy images recursively via bash
Hi guys, was wondering how i would go about recursively copying jpg's and gif's from one directory to another. The cp command doesnt seem to work with file types i.e $ cp -r src/*.jpg dest/, and also i'd like to be able to copy all jpgs and gifs at once.
Thanks! |
Do you need to keep the directory structure? If not, the find command will do what you need:
Code:
find /src -regextype posix-extended -regex '.*(jpg|gif)' -exec cp {} /dest \; |
Thanks for the reply Gilead, looks good but yes i need to keep the structure.
|
You can do it with rsync like this:
Code:
rsync -a --include "*/" --include "*.jpg" --exclude "*" src/ dest/ If rsync is not installed (it should be because it's so über useful), you can do it using cpio in "copy pass" mode, using find to locate the files: Code:
cd src |
Quote:
Code:
# ls -1 |
And since TMTOWTDI:
Code:
find . -regextype posix-extended -regex '.*\.(jpg|gif)$' -print |
Ok thanks gilead,
the rsync seems to work. Mind you the first time i ran i got "rsync reports some files could not be transferred (code 23)".. The second time i ran it (after i deleted what was created) no errors. Weird. |
All times are GMT -5. The time now is 08:54 AM. |