Wednesday 11 July 2012

Linux Tips - Delete the same file from multiple directories


Every now and then you find yourself in a situation where you want to perform a simple operation, like removing/deleting a particular file from multiple folders, and you don't know how to do it.

A quick example that comes to my mind is the following:
Assume that under a version control software you have a directory structure and you want to copy a specific folder along with its contents.
More often than not, version control software will create hidden (or not) files within your folder and its subfolders to keep track of the history of events like additions of new files and updates or deletions of existing files, etc.

Once you copy the desired folder you most probably want to get rid of the version control specific files.

The following command demonstrates an easy way of doing that under a Linux environment:


find . -type f -name "" -exec rm -f {} \;

This command has been of great help to me and I am sure it will help others as well...

Enjoy...