Removing all files located

Sometimes, we need to delete all the files searched by locate command. What we do ( i do this before :P) is to go to those files path and delete them manually, one by one, which was a tedious job.

So to do this using command, type:

$locate <search-string> | xargs rm -Rf

What xargs does is take a line from the input, and append it to another command, executing that other command for every line in the input. So by typing locate foobar | xargs rm -f, the output of the locate command will be patched onto the end of the rm -f command, and executed for each line produced by locate foobar.

You can verify the result by executing $locate <search-string>  command again. If you still see those files after terminal, Probably case is your database of locate command is not updated after removing files, so to do this you need to give command to update the database of locate. I had same case and my friend mandeep helped me with this command 🙂

$sudo udpatedb



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.