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

reference: http://askubuntu.com/a/18393

Advertisements

About Jasleen Kaur

Hi, I am Jasleen kaur, a Computer Science Student.
This entry was posted in Linux, Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s