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


#!/bin/bash
#Author: Surendra kumar Anne(surendra@linuxnix.com)
#Purpose: To find executables in a given folder and remove them.
#Date/Time:09-Feb-2010.08:06
echo “Please specify the directory, from which you want to delete the executables”
read DIRVAL
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 it’s 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.
 

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.