Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My queston is kind off a basic * nautilus at time cant do well at recursive search & related operations...

I want to search files having name libre in them & then delete them... I am half done here & cant find a relaiable way to delete files especially when filenames have white spaces in them...

find -iname *libre*

this will search the files but lets say a file is 'Libre Office Word' now it has white spaces can you guide how to delete such files too?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You can use the -delete option if your version of find supports it or you can use rm in the -exec options.

find -iname '*libre*' -delete       # GNU find
find -iname '*libre*' -exec rm {} + # POSIX

Note that you should quote the pattern. This prevents the shell from expanding it prior to being passed to the find command.

share|improve this answer
    
I'm not sure if OP wants also uppercase letters in the name (by the example given). –  vonbrand Jan 26 '13 at 5:46
1  
@vonbrand my understanding is the OP wanted "Libre Office Word' to match, but was using some method of deletion (such as xargs or a for loop) that broke on files with spaces. –  jordanm Jan 26 '13 at 5:49
    
@jordanm yes you identified my real position. OK so the -delete flag worked even for whitesapces. How can I also pass a file extension to this search I mean search for libre & *.desktop –  nightcrawler Jan 26 '13 at 6:11
1  
-iname is not POSIX. -delete is not POSIX but is not exclusive to GNU find. –  Stephane Chazelas Jan 26 '13 at 7:58
    
Also note that -delete deletes (non-empty) directories, while rm wouldn't. -delete (both with GNU and FreeBSD finds at least) implies -depth. –  Stephane Chazelas Jan 26 '13 at 8:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.