unix command

Unix Command to Find and Cleanup Older Files

A very frequent issue where all DBAs always comes across is filling up of server mount point. Once mount point utilization exhausts or becomes 100% full then your database or application will be hung.

In this post, we will learn different ways to filter out which files to clean-up.

1. Unix command to check the mount point status

[piyush@oraclecloud /p033 ]$ df -hP /p003

Filesystem   Size Used Avail Use% Mounted on

/p003    919G 902G 17G 99% /p003


2. Unix command to check the top used size files under /p033 mount point

[piyush@oraclecloud /p033]$ ls -ltr |head

total 40484

drwx——.  2 root root  4096 Nov 21 2016 test

-rwxrwxrwx.  1 root root 20569422 Nov 28 2016 finstall.zip

-rw——-.  1 root root 10145806 Nov 28 2016 installrpm.sh

-rw——-.  1 root root 10547066 Nov 28 2016 installdeb.sh

-rw-r–r–.  1 root root    0 Dec 7 2016 testfiles


3. Unix command to sort top 10 used files with size

du -hsx * | sort -rh | head -10

[piyush@oraclecloud /p033 ]$ du -hsx * | sort -rh | head -10

20G  home

6.2G  tmp

5.4G  opt

5.1G  usr

4.9G  var

170M  Agents

155M  roots

21M  etc

20M  install.sh

11M  installdeb.sh


4. Unix Command to Cleanup | Find files that are older than 30 days and delete them.

Ex- delete files from /p003 mount point

find /p003 -mtime +30 -exec rm {} \;


5. Search numbers of files that are older than 30 days

find /p003 -ctime +30 | wc -l

Either you can manually delete the top consumed files or move them to another mount point. The easiest way is to use unix Command to Cleanup files. Or you can use the find command to search and deleted files that are older than 30 days.

Happy Learning.


View- Add Prefix-Suffix To All Existing Files in Linux Directory 


Leave a Reply

%d bloggers like this: