2

.Hi. I have a bunch of jpgs in 100s of subfolders , I know I can move them all with this command

find -type f -iname "*.jpg" -exec mv -av {} /home/root/private/pics/ \; 

But my all my jpgs are like this in each subfolder

0001.jpg  
0002.jpg  
0003.jpg  
0004.jpg  
0005.jpg  

and so up to 2500.jpgs in one folder

So it overwrites them when putting them into the directory 'pics' because most of them have the same file name

How can i rename or avoid the same JPG image names being overwrited with this command?

find -type f -iname "*.jpg" -exec mv -av {} /home/root/private/pics/ \; 
2
  • drop the -a please.
    – Rinzwind
    Apr 26, 2021 at 21:38
  • Why do you want all files in one single directory? I have a lot of pictures too, and I store them in a directory tree with sub-directory paths .../year/month/day for example .../2021/07/20. Several tools can easily manage the pictures in such a directory tree. It works well also with some other directory tree, probably also what you have (or had).
    – sudodus
    Jul 20, 2021 at 13:54

2 Answers 2

3

Use the numbered when using mv

numbered, t
make numbered backups

man mv

mv --backup=TYPE with type being 1 of these:

  • none, off never make backups (even if --backup is given)
  • numbered, t make numbered backups
  • existing, nil numbered if numbered backups exist, simple otherwise
  • simple, never always make simple backups
5
  • Very new to linux should the command look like this: find -type f -iname "*.jpg" -exec mv -av {} /home/root/private/pics/ \; numbered, t ?
    – 1014Noob
    Apr 26, 2021 at 15:58
  • Getting this error: find -type f -iname "*.jpg" -exec mv numbered, t -av {} /home/root/private/imgs/ \; ERROR :: Try 'mv --help' for more information. mv: invalid option -- 'a'
    – 1014Noob
    Apr 26, 2021 at 16:08
  • it is mv --backup=numbered ;-)
    – Rinzwind
    Apr 26, 2021 at 16:11
  • find -type f -iname "*.jpg" -exec mv -av --backup=numbered {} /home/user/private/imgs/ \; still giving me same error :mv: invalid option -- 'a' Try 'mv --help' for more information.
    – 1014Noob
    Apr 26, 2021 at 16:23
  • 1
    @1014Noob mv doesn't have a -a option.
    – user986805
    Apr 26, 2021 at 19:54
-1

I would suggest using Thunar package manager, to rename and relocate files in bulk. You can install it with this command: sudo apt-get install -y thunar

1
  • Let me know if this helps.
    – Jeff
    Apr 26, 2021 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.