Results 1 to 2 of 2
Hi, I have a simple problem I was surprised not to figure out. Just a general Unix question. I have a bunch of photos on my computer sorted into folders, ...
- 12-27-2008 #1Just Joined!
- Join Date
- Jan 2007
- Posts
- 33
automatic renaming with cp?
Hi, I have a simple problem I was surprised not to figure out. Just a general Unix question. I have a bunch of photos on my computer sorted into folders, and I'd like to dump them all onto my thumb drive using cp. But I want to take them out of their sorted folders, just putting them all in one place. I can accomplish this with
cp -R */*.jpg /Volumes/NO\ NAME/
but 1) this only takes the top-level photos, eg it gets ./old/photo001.jpg but not ./school/before/P092738.jpg. This isn't so hard to work around but the real problem is 2) it overwrites photos of the same name, e.g. it copies ./old/photo001.jpg and then ./summer/photo001.jpg and overwrites the other photo001.jpg.
Can anyone think of a good quick single-command way of doing what I want? I'm thinking there should be a smart way of renaming the files as they're copied, I'd be happy with inserting large numbers in the filename but something like renaming ./old/photo001.jpg to old-photo001.jpg would work too.
Any way I can do this without writing a script?
- 12-27-2008 #2
For the first problem, this is easily solveable by using find instead of cp:
This will find all files in the subtree starting in the current directory whose name ends in '.jpg'. It will then execute the given cp command, replacing {} with the each file.Code:find . -iname '*.jpg' -exec cp '{}' /Volumes/NO\ NAME/ \;
As for the second problem, I checked the man page, and it looks like you might want to experiment with the --backup option.
Good luck!DISTRO=Arch
Registered Linux User #388732


Reply With Quote