In most companies, System Admin takes care of space issue on servers. They have tools or scripts to monitor the disk space usages to plan the storage accordingly and avoid server failure. I use Linux to host my Oracle databases in a sand environment and it is essential to know Linux inside out even though you are the database professional. You will need to know the intermediate skills like that of a System Admin to maintain your Linux Server. One critical task of System Admin is to monitor storage usage and report it to users to reclaim/recycle or ask for additional space.
When reaching out to users for space usage, it is always a good idea to get the list of top offenders and reach out to them before reaching out to all users. We will discuss to find top files and directories, file size and space used. These are the Linux command which can be automated using a shell script to send alerts when the usage is at 80% to proactively monitor servers.
How to list file size?
I use -h option from the list command to display a more human-readable output
When reaching out to users for space usage, it is always a good idea to get the list of top offenders and reach out to them before reaching out to all users. We will discuss to find top files and directories, file size and space used. These are the Linux command which can be automated using a shell script to send alerts when the usage is at 80% to proactively monitor servers.
How to list file size?
I use -h option from the list command to display a more human-readable output
ls -lh
How to display top size files only? The below command displays top 10 big filesfind -type f -exec du -Sh {} + | sort -rh | head -n 10
How to list top 10 big files and folders in your present working directory (pwd)?du -a | sort -n -r | head -n 10
Alternative: with human readable optiondu -sh direcory name
How to list top 10 files & folder in a home directory?du -a /home | sort -n -r | head -n 30
How to list top files from all the directories in human readable format?du -hs * | sort -rh | head -5
How to find the largest files in a directory?ls -lSr
ls -lSr | less
ls -lSr | head -10
How to find the smallest files in a directory?
ls -lSr
ls -lSr | less
ls -lSr | tail -10
By now, you may have figured out there are just two commands we played with to find what we need. Those two are ls and du Linux commands and their options. These are the Linux commands I learned over the years from Linux Guru online and in person and I would like to thank them for their time and sharing their knowledge with everyone. I hope you find these commands helpful and please share our community if you know any better commands than what was discussed here.
Interested in working with me? I can be reached at pbaniya04[at]gmail.com for any questions, consulting opportunities or you may drop a line to say HELLO. Thank your again for visiting my blog and looking forward to serving you more.
Have a Database-ious Day!
Have a Database-ious Day!
No comments