Ubuntu tricks: Search and delete

Have you came across the times when you installed something and got screwed that you cannot uninstall? The only solution is to recursively search and delete, at least to remove the files that are unnecessarily clogging your system. That might be harder only if you don’t know this little trick. This is one of may be many alternatives. If you know something else, please comment something on the post.
Now thanks to find, we can find files and also to exec, we can execute commands. Now I came a long this after installing Grisbi and I could not uninstall and I was unhappy. After all trials to reinstall and purge fail I resolved to do search and delete. Note, it is important to be careful with what you are searching. For example, searching *desktop* will search all .desktop files and you might find all shortcuts and launcher gone or not working (because it will then delete them). So be careful. Here is command I used to remove the all of grisbi files!
sudo find / -type f -iname “Grisbi*” -exec sh -c ‘rm -rfv “{}”‘ \;

Here are shortexplanations:
sudo – Elevate the command to execute as root (admin if you are still windowish)
find – Obviously the find command itself, now with sudo it will execute as root. We need root access to be able to search restricted directories and delete things found
-type f – we specify file as regular. You can find more types in the GNU find docs
iname – specify name ignoring case. Removing I, will make find case sensitive
“Grisbi*” – obviously, what do you want to search. Again, be careful here!
-exec sh -c – in short it mean you want to execute shell command. You can use also bash instead of sh
‘rm -rfv “{}”‘ – the command you want shell to execute. Note that will be replaced
by “found stuff”. If it found grisbi.desktop then command is expanded to rm -rfv grisbi.desktop
\; – this just terminates the exec command

you may use . Instead of / to search for current directory or just whole path like /home/metime/Documents
Enjoy and use with care


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 )

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