LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This 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

Tags used in this thread
Popular LQ Tags , , ,

Reply
 
Thread Tools
Old 03-06-2009, 04:49 PM   #1
smudge|lala
Member
 
Registered: Jan 2004
Location: UK & Canada
Distribution: Sabayon | Mint | Ulteo
Posts: 145
Thanked: 0
BASH search and move batches


[Log in to get rid of this advertisement]
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

smudge|lala is offline  
Tag This Post , , ,
Reply With Quote
Old 03-06-2009, 05:00 PM   #2
druuna
Senior Member
 
Registered: Sep 2003
Location: netherlands
Distribution: lfs
Posts: 3,269
Thanked: 78
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 05:02 PM..
druuna is offline     Reply With Quote
Thanked by:
Old 03-06-2009, 05:25 PM   #3
smudge|lala
Member
 
Registered: Jan 2004
Location: UK & Canada
Distribution: Sabayon | Mint | Ulteo
Posts: 145
Thanked: 0

Original Poster
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.
smudge|lala is offline     Reply With Quote
Old 03-06-2009, 05:49 PM   #4
druuna
Senior Member
 
Registered: Sep 2003
Location: netherlands
Distribution: lfs
Posts: 3,269
Thanked: 78
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.
druuna is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 Off
HTML code is Off


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


All times are GMT -5. The time now is 09:43 PM.

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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration