Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-14-2007, 10:45 AM
|
#1
|
|
Member
Registered: Sep 2005
Location: Birmingham / Bath Uk
Distribution: Kubuntu 8.10, Debain 4.0
Posts: 86
Rep:
|
find and delte commands
Ive had a look around and I'm having a little bit of trouble with the find and delte command, I dont know how to make the recurrsive (if thats the right word, I mean go into every folder and execute)
like the:
delete /s command in windows.
and also I dont know how to use the find command to find a file recurrsivly, and how to excluse certain extentions.
eg: I want to find all files in a folder + subfolders that dont end with .mp3, .wma, or .m4a
would this be:
find /Music/*.* !name-*.mp3 !name-*.wma !name-*.m4a
??
Thanks for your help in advance
|
|
|
|
03-14-2007, 12:43 PM
|
#2
|
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,570
|
This might work:
find /Music -r -type f -name "<filename>.*"--exclude .mp3 --exclude .wma -exec rm -f {} \;
where:
/Music is the top level directory to begin.
-r is recursive
-type f means regular file, as opposed to binary, block, etc.
-name "<filename>" is the basename of the file in quotes
exclude selected by file extension
-exec rm -f {} \; to remove the matches to the search pattern after the excluded files are de-selected.
More experienced heads will probably give you a more elegant solution.
Before trying this on your system, I'd suggest making a test directory with test files (same name, different extensions) and run the find command given above on the test directory to be certain it will work as expected.
Last edited by bigrigdriver; 03-14-2007 at 12:55 PM.
|
|
|
|
03-14-2007, 12:51 PM
|
#3
|
|
Member
Registered: Sep 2005
Location: Birmingham / Bath Uk
Distribution: Kubuntu 8.10, Debain 4.0
Posts: 86
Original Poster
Rep:
|
when i tried:
find /Music -r -type f --exclude .mp3 --exclude .wma | grep '*.*'
i got: find: invalid predicate `-r'
when i got rid of -r
i got: find: invalid predicate `--exclude'
when i tried:
find Music/ -type f | grep '*.*'
it seemed to run for a second and then finish, printing no results
|
|
|
|
03-14-2007, 01:09 PM
|
#4
|
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,570
|
My bad. Mixed parts of two commands. I apologize.
find /Music -type f -maxdepth 3 | grep 'filename' --exclude .mp3 --exclude .wma | -exec rm -f {} \;
maxdepth 3 (search three levels down)
You may have to enclose the excluded pattern in quotes. Try it both ways.
Make a test directory with test files (same name; different extensions) to test this on to verify that it will work.
Last edited by bigrigdriver; 03-14-2007 at 01:10 PM.
|
|
|
|
03-14-2007, 01:12 PM
|
#5
|
|
Member
Registered: Sep 2005
Location: Birmingham / Bath Uk
Distribution: Kubuntu 8.10, Debain 4.0
Posts: 86
Original Poster
Rep:
|
ok i worked it out:
find -not -name *.mp3 -a -not -name *.m4a -a -not -name *.wma
would get what I wanted, and this could also be used to delte the files by using the find commands ability to execute stuff to the files it finds.
Thanks 
|
|
|
|
03-14-2007, 01:19 PM
|
#6
|
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,570
|
And I've learned yet another variation on the theme of 'find and delete'. Thank you.
|
|
|
|
03-14-2007, 01:43 PM
|
#7
|
|
Member
Registered: Sep 2005
Location: Birmingham / Bath Uk
Distribution: Kubuntu 8.10, Debain 4.0
Posts: 86
Original Poster
Rep:
|
I think I might have to make an alias for it just so i can type "searchanddestroy" in at command line for it :P
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:42 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|