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.) ?
try
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.
[EDIT]
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.
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).
because of the amount of files, write a script that you can get control of your files.
#!/bin/bash
working_dir=
move_to=
if [[ -z "$1" ]] ;
then
{
echo "How many file you want to run this time?"
exit
}
fi
count=$1
echo "$working_dir"
while read f ;
do
#echo "$f"
#new dir struct
new_place=${f/$working_dir/$move_to}
echo "NEW: $new_place"
filename=$(basename "$f")
extension=${filename##*.}
filename=${filename%.*}
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
}
fi
((count++))
[[ "$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.