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.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018