4

My files have the following structure:

11
--11a
-----a.jpg
-----b.jpg
-----....
--11b
-----d.jpg
-----g.jpg
...

I want to have all the .jpg files in one folder:

11
-a.jpg
-b.jpg
-d.jpg
-g.jpg
...

Basically I have subfolders with many .jpg files and I want to move all of them to one directory (e.g. parent).

I have tried: mv */*.jpg all but I get -bash: /bin/mv: Argument list too long.

Some posts suggest xargs and some other the find solution but unfortunately nothing seems to be working for me.

2 Answers2

6

If the file names are unique, use:

find {base folder}/11 -name "*.jpg" -exec mv {} {base folder}/11/ \;

where {base folder} is where the directory 11 resides.

This runs the mv command on each file in turn: it will be a lot slower than moving all the files in a single mv command, but there will be no restrictions on the length of the argument list.

If some of the file names could be in upper case, you can use -iname instead of -name. You can also add -n to make sure you do not overwrite a file which has been moved already (you need to check that your mv has this option - if not use -i, though this will prompt on conflicts).

You can get rid of any empty directories with:

rmdir {base folder}/11/*

You will need to investigate any directories that remain after this command.

AFH
  • 17,958
-2

This should be as easy as "mv /.your_extension ./"