preload preload preload preload

Shell Script to delete unwanted files and directories

#!/bin/bash
cd /home/shahid/                # Change the dectory to the specified location
monit stop all                      # Stop all the process
rm -rf log/*                           # Deletes all the files inside the directory log

rm -rf dump/processed/*     # Deletes all the files inside the directory dump/processed/

rm -rf dump/s3/*                  # Deletes all the files inside the directory dump/s3/
#rm -rf dump/02-*               # Deleting the directory starting with 02-
#rm -rf dump/03-*               # Deleting the directory starting with 03-
#rm -rf dump/12-*               # Deleting the directory starting with 12-*

months=( 01 02 03 04 05 06 07 08 09 10 11 12 ) # Declare an array named months.

seperator=”-”                        # Date seperator 13-02-2008
star=”*”                                 # Specify * to

for ((  i = 0 ;  i < 31;  i++  ))      # For loop to check directories starting with the name 01-, 02-, .., 12-.
do
var1=${months[$i]}$seperator$star   # Gets all the files & directories starting with 01-, 02-,…,12-
#    echo $var1
for dir in $var1                    # Gets each file and directories seperatly
do
if [ -d $dir ]                     # Checks for directory if yes
then                               #then
rm -rf $dir                  # Only deletes the directories
fi                                    # End of If
done                                  # End of second for loop
done                                     # End of First for loop

monit start all                        # Starting all the process
  • Share/Bookmark
  • Leave a Reply

    * Required
    ** Your Email is never shared