Monday 23 May 2016

Findiing & Removing (Deleting) Files by 'n' Dates in LINUX



Finding & Removing (Deleting) Files by 'n' Dates in LINUX

There are three times associated with a file

·         atime  - last access time
   
·         ctime  - last status change time

·         mtime  - last modify time

Remove all files from /home/dpafumi older than 5 days:
$ find /home/dpafumi -type f -mtime +5 -exec rm -f {} \;

Print out what files from /home/dpafumi older than 5 days:
$ find /home/dpafumi -type f -ctime +5 -print

Finding the top 5 largest files
$ find . -ls | sort -nrk 7 | head -5

Find files larger than 100MB
$ find . -size +100000k

Delete audit records that’s older than 30 days
$ find $ORACLE_HOME/rdbms/audit -name "*.aud" -mtime +30 -exec rm {} \;

Delete files in /tmp that’s older than 30 days
$ find /tmp -group dba -type f -mtime +5 -exec rm -f {} \; find /tmp/dba -group dba -type f -mtime +5 -exec rm -f {} \;

Delete *.trc files more than 5 days old
$ find $TRACE_DIR -name '*.trc' -type f -mtime +5 -exec rm {} \;

Display top 5 largest files in a current directory
$ ls -alS | head -5

Largest space-consuming directories (Does not include sub-directories)
$ du -Sm . | sort -nr | head -5

Report the sum of space consumed by a directory and its subdirectories
$ du . | sort -nr | head -5

List files in a directory greater than 300M
$ ls -l | awk '{if ($5 >314572800) print $0}' |sort +4

4 comments:

  1. Nice collection ... it's vry useful command . It's use daily working environment ...

    ReplyDelete
  2. Nice collection ... it's vry useful command . It's use daily working environment ...

    ReplyDelete