LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   BASH search and move batches (https://www.linuxquestions.org/questions/linux-general-1/bash-search-and-move-batches-709708/)

smudge|lala 03-06-2009 03:49 PM

BASH search and move batches
 
Not a command I have thought about previously, but lets say I moved all my files from my main machine to my external drive and now have .mp3 files in different places, how would I search for all on the system or a set drive and move the lot to a new dir?

Be really handy for images, video and more!

Even better would be if I can ignore any that are smaller than x or bigger than y

:)

druuna 03-06-2009 04:00 PM

That looks like a job for the find command:

find . -type f -size +200k -size -4M -iname "*.mp3" -exec cp {} /tmp \;

This will:
- from the current position . (the dot after find)
- look for files (-type f)
- ending in mp3, it ignores case (-iname "*.mp3")
- that are bigger then 200k (-size +200k)
- smaller then 4Mb (-size -4M)
All that is found will be copied to /tmp.

I know you want to move, but try using cp until you are sure this works the way you want it to. If it does replace cp with mv.

It has one potential 'problem', files with the same name will be overwritten (destination side) and you will be left with the last version copied/moved......

Hope this helps.

smudge|lala 03-06-2009 04:25 PM

That's brilliant thank you. I wondered about incorporating
Code:

cat set*.mp3 | sort | uniq
or
Code:

md5sum * | sort | uniq -d -w32 | cut -d' ' -f3 | xargs rm
somehow to try and filter uniques but not sure how to implement. Could be great for hunting many things.

Last time I tried to use md5sum to find unique files it became slow and gave an error. Obviously large files would be hell for md5sum but good for .txt

Then the uniq command should do this but I'm rusty on how unique this gets. Thanks for your notes above.

druuna 03-06-2009 04:49 PM

Hi again,

If overwriting files is not wanted you could start with using cp's (or mv's) -i option (prompt before overwrite). That gives you some sort of control, and you end up with a list of what's named the same. But this involves some human intervention.....

Anyway, hope this helps.


All times are GMT -5. The time now is 03:57 PM.