Tuesday, February 9, 2010

Script to remove executables

Some times we require to remove executables from perticular directories.. This script will show how to do that..

#Author: Surendra kumar Anne(surendra@linuxnix.com)
#Purpose: To find executables in a given folder and remove them.
echo "Please specify the directory, from which you want to delete the executables"
find $DIRVAL -executable -type f -exec rm -rf {} \;
echo "deleted all the executables from $DIRVAL"

Let me explain the above script..
first line of the shell script is always she-bang statement, which is required by the system to know what type of script is this.. from the first line your system will come to know its a bash script.
And next three lines are used for specifying Author,Purpose and Date(these three lines are not mandatory but a good scripting expert will provide them).
Here echo commend is used to display a question to user.. Then user should provide from which directory he wants to delete the executables.

Here i am using find command with -executable and -type option to find only executable files and then i am feeding them to find builtin -exec which will remove all the executables using rm command.


Post a Comment