LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-06-2009, 03:49 PM   #1
smudge|lala
Member
 
Registered: Jan 2004
Location: Hertford
Distribution: Mint | Sabayon
Posts: 151

Rep: Reputation: 15
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

 
Old 03-06-2009, 04:00 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
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.

Last edited by druuna; 03-06-2009 at 04:02 PM.
 
Old 03-06-2009, 04:25 PM   #3
smudge|lala
Member
 
Registered: Jan 2004
Location: Hertford
Distribution: Mint | Sabayon
Posts: 151

Original Poster
Rep: Reputation: 15
Lightbulb

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.
 
Old 03-06-2009, 04:49 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
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.
 
  


Reply

Tags
move, bash, search, sort


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to tell bash to move files to another folder? hq4ever Linux - Newbie 10 12-30-2010 03:15 AM
LXer: Yahoo Recruits Dev Army With Open Search Move LXer Syndicated Linux News 0 07-11-2008 01:11 PM
Bash development - move chmod options to bash jhwilliams Programming 9 06-26-2007 12:13 PM
Move a job from one bash shell to another? marktaff Linux - General 3 01-13-2006 07:22 PM
help with writing scripts or batches pls Elvampira Linux - General 3 08-07-2003 04:35 AM


All times are GMT -5. The time now is 09:31 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration