Menu

Find Out Top Directories and Files (Disk Space) in Linux

As a Linux administrator, you must periodically check which files and folders are consuming more disk space. It is very necessary to find the unnecessary junks and free up them from your hard disk.2. List Files Based on Last Access Time
This brief tutorial describes how to find the largest files and folders in the Linux file system using du and find command. If you want to learn more about these two commands, then head over to the following articles

How to Find Biggest Files and Directories in Linux
Run the following command to find out top biggest directories under /home partition.
# du -a /home | sort -n -r | head -n 5
Example:--
root@hackthesec:/home/hackthesec# du -a /home | sort -n -r | head -n 5
22302276 /home
22301772 /home/hackthesec
11271352 /home/hackthesec/Downloads
4623604 /home/hackthesec/Desktop
3287836 /home/hackthesec/.thunderbird-trunk
The above command displays the biggest 5 directories of my /home partition.

Find Largest Directories in Linux
If you want to display the biggest directories in the current working directory, run:
# du -a | sort -n -r | head -n 5
Let us break down the command and see what says each parameter.
  1. du : command: Estimate file space usage.
  2. a : Displays all files and folders.
  3. sort command : Sort lines of text files.
  4. -n : Compare according to string numerical value.
  5. -r : Reverse the result of comparisons.
  6. head :Output the first part of files.
  7. -n : Print the first ‘n’ lines. (In our case, We displayed first 5 lines).
Some of you would like to display the above result in human readable format. i.e you might want to display the largest files in KB, MB, or GB.
# du -hs * | sort -rh | head -5
The above command will show the top directories, which are eating up more disk space. If you feel that some directories are not important, you can simply delete few sub-directories or delete the entire folder to free up some space.

To display the largest folders/files including the sub-directories, run:
# du -Sh | sort -rh | head -5
Find out the meaning of each options using in above command:
  1. du Command: Estimate file space usage.
  2. -h : Print sizes in human readable format (e.g., 10MB).
  3. -S : Do not include size of subdirectories.
  4. -s : Display only a total for each argument.
  5. sort command : sort lines of text files.
  6. -r : Reverse the result of comparisons.
  7. -h : Compare human readable numbers (e.g., 2K, 1G).
  8. head : Output the first part of files.
Find Out Top File Sizes Only
If you want to display the biggest file sizes only, then run the following command:
# find -type f -exec du -Sh {} + | sort -rh | head -n 5
To find the largest files in a particular location, just include the path besides the find command:
# find /home/hackthesec/Downloads/ -type f -exec du -Sh {} + | sort -rh | head -n 5
The above command will display the largest file from                 /home/hackthesec/Downloads directory.

www.hackthesec.co.in

About Author:


I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Next
Newer Post
Previous
Older Post

0 comments:

Post a Comment

 
Top