Find the answer to your Linux question:
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, ...
  1. #1
    Just 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?

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    For the first problem, this is easily solveable by using find instead of cp:
    Code:
    find . -iname '*.jpg' -exec cp '{}' /Volumes/NO\ NAME/ \;
    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.

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...