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 |
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. |
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 |
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. |
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 :newbie: |
And I've learned yet another variation on the theme of 'find and delete'. Thank you.
|
I think I might have to make an alias for it just so i can type "searchanddestroy" in at command line for it :P
|
All times are GMT -5. The time now is 08:42 AM. |