Copying a bunch of images to one directory. - shell
This is a discussion on Copying a bunch of images to one directory. - shell ; In stead of reinventing the wheel, someone has to have needed to do this in the past. Does this command line code exist somewhere I can download/look at. I have a directory with over a hundred directories of images in ...
![]() |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| this in the past. Does this command line code exist somewhere I can download/look at. I have a directory with over a hundred directories of images in them. I need to copy all the .png, .gif. JPEG, .jpg files to another directory in order to burn a CD for a slide show at a Christmas party. Can anyone help TIA Dave |
|
#2
| |||
| |||
|
On 2007-11-24, Dave Kelly wrote: > > > In stead of reinventing the wheel, someone has to have needed to do > this in the past. Does this command line code exist somewhere I can > download/look at. > > I have a directory with over a hundred directories of images in them. > I need to copy all the .png, .gif. JPEG, .jpg files to another > directory in order to burn a CD for a slide show at a Christmas > party. If just copying them to the other directory is fine: cp ./*.png ./*.gif ./*.JPEG ./*.jpg /path/to/other/directory You may also want to look at mkisofs. -- Chris F.A. Johnson, author Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
#3
| |||
| |||
|
Dave Kelly > In stead of reinventing the wheel, someone has to have needed to do > this in the past. Does this command line code exist somewhere I can > download/look at. > > I have a directory with over a hundred directories of images in them. > I need to copy all the .png, .gif. JPEG, .jpg files to another > directory in order to burn a CD for a slide show at a Christmas > party. find -name '*.jpg' -o -name '*.jpeg' | xargs cp --target-directory=/tmp/myporn or cp */*.{jpg,jpeg} /tmp/myporn :-) -- William Park BashDiff: Super Bash shell http://freshmeat.net/projects/bashdiff/ |
|
#4
| |||
| |||
|
Chris and William........... I may have worded my problem badly. > > I have a directory with over a hundred directories of images in them. Does you examples step down into each directory? Return to the main directory and continue looking for the next directory? Thanks for the feedback. Dave |
|
#5
| |||
| |||
|
Dave Kelly wrote: > Chris and William........... > > I may have worded my problem badly. > > >>>I have a directory with over a hundred directories of images in them. > > > Does you examples step down into each directory? Return to the main > directory and continue looking for the next directory? William's 'find' example collects the files from all subdirectories; wasn't that what you wanted? Did you try the suggestions? Janis > > Thanks for the feedback. > Dave > > |
|
#6
| |||
| |||
|
On Nov 24, 4:40 pm, Janis Papanagnou wrote: > William's 'find' example collects the files from all subdirectories; > wasn't that what you wanted? Did you try the suggestions? > > Janis T hat is exactly what I want. No I did not try the suggestion because of my ignorance of how find works. Will do so immediatly. If things do not work as expected, I will come back for further education. Otherwise assume everything is as it should be. ( As it is in all cases where there in no operator error.) Let me say thanks to everyone on this group for all the help they have given me over the past 8 years. This old man appreciates it. Dave |
|
#7
| |||
| |||
|
On Nov 24, 4:40 pm, Janis Papanagnou wrote: > William's 'find' example collects the files from all subdirectories; > wasn't that what you wanted? Did you try the suggestions? > > Janis > Tried this: find -name '{*.jpg,*.png,*.JPG,*.gif}' -o -name '{*.jpg,*.png,*.JPG,*.gif}' | xargs cp --target-directory=~/ xmasparty07 And got this error cp: missing file argument Tried this: SilverNail:~/tffwebsite/httpdocs/images# find -name '*.jpg' -o -name '*.jpg' | xargs cp --target-directory=~/xmasparty07 And got this error cp: `~/xmasparty07': specified destination directory does not exist Tried this: find -name '*.jpg' --o name '*.jpg' | xargs cp --target-directory=/ root/xmasparty07 And got this error cp: cannot stat `enhanced': No such file or directory cp: cannot stat `1.jpg': No such file or directory cp: cannot stat `./Belize2005/Norbert': No such file or directory cp: cannot stat `Bonefish': No such file or directory cp: cannot stat `at': No such file or directory So I tried --o name "'*.jpg'" and -o name '"*.jpg"' and still get the cannot stat errors. |
|
#8
| |||
| |||
|
On Sun, 25 Nov 2007 17:28:35 -0800 (PST), Dave Kelly | On Nov 24, 4:40 pm, Janis Papanagnou | wrote: |> William's 'find' example collects the files from all subdirectories; |> wasn't that what you wanted? Did you try the suggestions? |> |> Janis |> | Tried this: | find -name '{*.jpg,*.png,*.JPG,*.gif}' -o -name | '{*.jpg,*.png,*.JPG,*.gif}' | xargs cp --target-directory=~/ | xmasparty07 | And got this error | cp: missing file argument | | Tried this: | SilverNail:~/tffwebsite/httpdocs/images# find -name '*.jpg' -o -name | '*.jpg' | xargs cp --target-directory=~/xmasparty07 | And got this error | cp: `~/xmasparty07': specified destination directory does not exist | | Tried this: | find -name '*.jpg' --o name '*.jpg' | xargs cp --target-directory=/ | root/xmasparty07 | And got this error | cp: cannot stat `enhanced': No such file or directory | cp: cannot stat `1.jpg': No such file or directory | cp: cannot stat `./Belize2005/Norbert': No such file or directory | cp: cannot stat `Bonefish': No such file or directory | cp: cannot stat `at': No such file or directory | | So I tried --o name "'*.jpg'" and -o name '"*.jpg"' and | still get the cannot stat errors. The stat errors look like the typical result of files with spaces in their names. Find locates them correctly, but xargs breaks them up on the space characters. Assuming your versions support the options, try this: find -name '*.jpg' -o -name '*.gif' -print0 | \ xargs -0 cp --target-directory=/root/xmasparty07 The '-print0' and '-0' contain a numeric 0, not the upper case letter O This uses a NULL character (ASCII zero) as the word separator instead of spaces. -- Reverend Paul Colquhoun, ULC. http://andor.dropbear.id.au/~paulcol Asking for technical help in newsgroups? Read this first: http://catb.org/~esr/faqs/smart-questions.html#intro |
|
#9
| |||
| |||
|
On 26 Nov., 02:28, Dave Kelly > On Nov 24, 4:40 pm, Janis Papanagnou > wrote:> William's 'find' example collects the files from all subdirectories; > > wasn't that what you wanted? Did you try the suggestions? > > > Janis > > Tried this: > find -name '{*.jpg,*.png,*.JPG,*.gif}' -o -name > '{*.jpg,*.png,*.JPG,*.gif}' | xargs cp --target-directory=~/ > xmasparty07 > And got this error > cp: missing file argument > > Tried this: > SilverNail:~/tffwebsite/httpdocs/images# find -name '*.jpg' -o -name > '*.jpg' | xargs cp --target-directory=~/xmasparty07 > And got this error > cp: `~/xmasparty07': specified destination directory does not exist > > Tried this: > find -name '*.jpg' --o name '*.jpg' | xargs cp --target-directory=/ > root/xmasparty07 > And got this error > cp: cannot stat `enhanced': No such file or directory > cp: cannot stat `1.jpg': No such file or directory > cp: cannot stat `./Belize2005/Norbert': No such file or directory > cp: cannot stat `Bonefish': No such file or directory > cp: cannot stat `at': No such file or directory > > So I tried --o name "'*.jpg'" and -o name '"*.jpg"' and > still get the cannot stat errors. Does the man page of your find command specifies to write two slashes with option -o? Option 'name' requires a slash -name. Quoting of the find arguments is necessary to prevent the shell to expand the names to a matching file in the current directory and thereby producing errors or wrong results; use just one pair of quotes, either single or double (the latter in case you want to have shell variables inside the string expanded before find is called). Try find . -name "*.jpg" -o -name "*.gif" -o -name "*.png" -print0 | xargs -0 cp --target-directory=/root/xmasparty07 Add more filename (patterns) by using a -o ("or") and -name. (The 0 is a zero digit in case your font obscures it.) Janis |
|
#10
| |||
| |||
|
The -exec option of find handles spaces in filenames correctly: find cp {} And it also works with non-GNU versions of find and cp. |
![]() |
« Previous Thread
|
Next Thread »
| Thread Tools | |
| Display Modes | |
| |
All times are GMT -4. The time now is 02:24 AM.




Linear Mode