Find Commands


find /tmp -user Sudhir (sort as per owner of the file)
find . -type f -name " "
find /app/ -name " " -print
find . -name set* | grep 6001 | - print
find . -size +150000 > log.txt
find . -mtime +10 -exec rm -rf {} \; (days)
find /opt/app/logs -name '*.log' -mtime +90 -exec rm {} \; (same directory has multiple type of files, and want to delete ONLY those with .log)
find /tmp -name '*.log' -mtime +30 -exec rm {} \;
find /tmp -name '*.log.1' -mtime +30 -exec rm {} \;
find . -name "*" -size +999999 -exec ls -ltr {} \;
find . -name "*" -exec grep -l "1995383" {} \; (to find an id in a file with in a folder)

------------------------------------------------------------------------------------------------------------
Find ten day old files
#/bin/ksh
echo "This script will put the names of ten day old files in /tmp in /tmp/checkold.txt file"
find /tmp -size 0 -atime +10 -exec ls -l {} \; > /tmp/checkold.txt
find /tmp -size 0 -atime +10 -exec rm -f {} \;


Find large files on System
---------
#!/bin/sh
# Script to find the big files on a disk. 
# Defaults and temporary info.
# This script send the output to a default printer
DiskName=${1:?Disk name not supplied.}
TMPFILE=/tmp/$LOGNAME.$$.txt
SysName=`uname -n`
 
echo \
        "Checking for large files on $SysName $DiskName.  " \
        "Output will be sent to default printer."
 
echo "\nNewer big files on $SysName $DiskName" >> $TMPFILE
find $DiskName -type f -mtime -3 -size +5000 -exec ls -ld {} \; \
        2>/dev/null | sort -n -k 5.1,5 >> $TMPFILE
 
echo "\nOlder big files on $SysName $DiskName" >> $TMPFILE
find $DiskName -type f -mtime +3 -size +5000 -exec ls -ld {} \; \
        2>/dev/null | sort -n -k 5.1,5 >> $TMPFILE
 
#change the following line if you want to put output to a file
#or anything.

lp -onb -olandscape $TMPFILE
rm $TMPFILE
 # End of script


Count files in directory (not hidden one's)
#!/bin/ksh
echo * | wc -w


Total Disk space in system in MB.
#!/bin/ksh
#This script will return the total disk space in system.
df -t | awk 'BEGIN {tot=0} $2 == "total" {tot=tot+$1} END {print (tot*512)/10000
00}'


Total used space in system in MB.
#!/bin/ksh
#This script tells total used space in a system
df | awk 'BEGIN {tot=0} {tot=tot+$4} END {print (tot*512)/1000000}'


Search for pattern in a file and return total count.
#!/bin/ksh
#This script  searchs the file passed as first argument to this command line and 
#prints total number found
grep $1 filename | awk 'BEGIN {tot=0} {tot=tot+$1} END {print (tot)}'


This command will find the core files with group name mycomp and delete them while also writing the name of deleted file in mycompcore.
#!/bin/ksh
find / -name core -group mycomp -print -exec rm -f {} \; >> mycompcore

No comments:

Post a Comment