Category Archives: Shell Code

Shell Script Loop

#!/bin/ksh
files="/etc/passwd /etc/group /etc/hosts"
for f in $files; do
   if  ! -f $f ]
      then
         echo "$f file missing!"
   fi
done

#!/bin/ksh
for car in $(cat car.txt)
do
   print "Current Car : $car"
done

#!/bin/ksh
for f in $(ls /tmp/*)
do
   print "Full file path  in /tmp dir : $f"
done

Linux Quick Finds

Finding Large Directories

look for large files with this command:

find . -type f -size +100000k -exec ls -lh {} \; | awk ‘{ print $9 “: ” $5 }’

This looks for files over 100MB, but other than datafiles there were very few files found. I knew I needed to look for large directories. Directories that had a large amount of small files. This command worked nicely:

du -h / | grep ^[1-9][0-9][0-9.]*G | sort -rn

From there I was able to find the directories that I needed to clear out.

Find and zip files newer than X minutes

find . -mmin -1620 -type f -name \*_lm[d,s]\*trc -print -exec zip /tmp/`hostname`_lm_files.zip {} \;