[SOLVED] Is it possible to use mv in terminal to recursivley move a certain...

I an trying to move files of a certain filetype from many folders to one folder of a specific filetype, such as MKV, MP3, AVI, PDF etc… etc…
I am using a file recovery program to recover files and it saves them in batches of around 500 of multiple filetypes.
What I want to do is put each filetype into their own folder.

I am currently doing this manually, which is going to take a lonnnnnng time as there’s nearly 1000 folders so far.

How can I do this in terminal using mv recursively (if it can do that).

I take it they files have extensions (so are searchable by name ‘*.mp3’ etc.) ?


find /path/to/directory/to/search -type f -iname "*.mp3" -exec mv {} /path/to/director/to/save \;

that’s a case insensitive search, so will move all files with .MP3 and .mp3 and .Mp3 and .mP3

if you want it case sensitive

find /path/to/directory/to/search -type f -name "*.mp3" -exec mv {} /path/to/director/to/save \;

you might want to test it first with cp (copy) instead of mv (move), so

find /path/to/directory/to/search -type f -iname "*.mp3" -exec cp {} /path/to/director/to/save \;

Personally I’d just use something like the GUI gnome-search-tool to search the location by extension … then copy/paste from the results window.

What I’ve done to move the contents of each folder to one folder so I can handle all the files easily, one extension at a time.
I used;

mv /media/pooky2483/INT-02/Recovered_Files/recup_dir.{841..880}/*.* /media/pooky2483/INT-02/Recovered_Files/MOVED

I found for some reason that I can only move the contents in blocks of 30 (why is this?)

I then used;

mv /media/pooky2483/INT-02/Recovered_Files/MOVED/*.jpg /media/pooky2483/INT-01/Recovered\ Files/JPG

And just changed the extension and repeated the command.

Just noticed an error and will edit in a min.
Fixed error.

I tried that program but it was taking far too long due to the amount of files… almost 500,000. It was taking over 24 hours and still going.

because of the amount of files, write a script that you can get control of your files.



if [[ -z "$1" ]] ; 
  echo "How many file you want to run this time?"
echo "$working_dir"

while read f ;
#echo "$f"
	#new dir struct
	echo "NEW: $new_place"
	filename=$(basename "$f")     

	echo $filename
	echo $extension
	echo $filename

if [[ "$extension"  == "mp4" ]] ;  then
	#mkdir here then move it
	#mkdir -p "$new_place"
	#mv "$f" "$new_place"
	echo "$f"
	echo "$extension
elif [[ "$extension"  == "png" ]] ;  then
	#mkdir here then move it
	echo "$f"
	echo "$extension

[[ "$count" -eq "$1" ]]  && exit
echo "count $count"

done <<<"$(find "$working_dir" -type f )" #-name "*.mkv" -o -name "*.mp4" -o -name "*.jpg")"

modify it to your needs.

Did it manually in the end.