Linux most used files

Find Top 10 Space Consuming Directories & Files On Linux & UNIX System

As Linux administrator, sometimes we need to know what directories and files are eating up all our disk space. Similarly, we should be able to discover a particular directory location on file system such /var, /tmp, /opt and /home etc.

In this article I will try to help you, to find top 10 space consuming directories and files in Linux system.

Although, there is no any shortcut command to find out the top space consuming directories and files on Linux system. However, We can use following three commands with pipes to do this.

  • du :- It estimates file space usage.
  • sort :- Sort lines of text files or given input data.
  • head :- Display first 10 files and output the first part of files.
  • find :- To search file.

Find Top 10 Space Consuming Directories and Files

Execute the below command at the shell prompt to find out top largest Files and Directories.

# du -a /var/spool/ | sort -n -r | head -n 10

You will get some output like below.

16888 /var/spool/ 13916 /var/spool/mqueue 2928 /var/spool/mail 2924 /var/spool/mail/root 16 /var/spool/anacron 8 /var/spool/cron 4 /var/spool/samba 4 /var/spool/plymouth 4 /var/spool/lpd 4 /var/spool/cron/root

OR, If you want output in human readable format follow the below command.

# cd /var/spool/ # du -hsx * | sort -rh | head -10

You will get some output like below.

14M mqueue 2.9M mail 16K anacron 8.0K cron 4.0K samba 4.0K plymouth 4.0K lpd 4.0K clientmqueue
  • du -h : Display sizes in human readable format.
  • du -s : Show total for each argument.
  • du -x : Skip directoried on different file system.
  • sort -r : Reverse the result of comparisons.
  • sort -h : Compare human readable numbers.
  • head -10 : Display the first 10 lines.
    OR
  • head -n10 : Display the first 10 lines.
Читайте также:  Android dalvik on linux

You can use above command only if GNU/sort is installed. For other UNIX systems should use the below command.

# for i in G M K; do du -ah | grep 1$i | sort -nr -k 1; done | head -n 11 17M . 14M ./mqueue 2.9M ./mail/root 2.9M ./mail 16K ./anacron 8.0K ./cron 4.0K ./samba 4.0K ./plymouth 4.0K ./lpd 4.0K ./cron/root 4.0K ./clientmqueue

Find top 10 space consuming files in a dirctory and its subdirectories

Follow the below GNU/find command.

# cd /var/www/web3/web/chat/ # find . -printf '%s %p\n'| sort -nr | head -10 978882 ./img/home/live2support_home_page.JPG 255488 ./images/crm/Thumbs.db 198535 ./images/integrations/core5.jpg 198535 ./images/e-commerce/core5.jpg 193173 ./img/table_tab.png 191214 ./images/e-commerce/ameri4.jpg 186588 ./images/e-commerce/ameri5.jpg 177152 ./images/awards/Thumbs.db 167702 ./images/e-commerce/ameri2.jpg 163989 ./images/integrations/BrandonHallGrp.png OR # find /var/www/web3/web/chat/ -printf '%s %p\n'| sort -nr | head -10 978882 /var/www/web3/web/chat/img/home/live2support_home_page.JPG 255488 /var/www/web3/web/chat/images/crm/Thumbs.db 198535 /var/www/web3/web/chat/images/integrations/core5.jpg 198535 /var/www/web3/web/chat/images/e-commerce/core5.jpg 193173 /var/www/web3/web/chat/img/table_tab.png 191214 /var/www/web3/web/chat/images/e-commerce/ameri4.jpg 186588 /var/www/web3/web/chat/images/e-commerce/ameri5.jpg 177152 /var/www/web3/web/chat/images/awards/Thumbs.db 167702 /var/www/web3/web/chat/images/e-commerce/ameri2.jpg 163989 /var/www/web3/web/chat/images/integrations/BrandonHallGrp.png

Skip the directories and only show files

You can also skip the directories and only show files , follow the below command.

# find /var/www/web3/web/chat/ -type f -printf '%s %p\n'| sort -nr | head -10 978882 /var/www/web3/web/chat/img/home/live2support_home_page.JPG 255488 /var/www/web3/web/chat/images/crm/Thumbs.db 198535 /var/www/web3/web/chat/images/integrations/core5.jpg 198535 /var/www/web3/web/chat/images/e-commerce/core5.jpg 193173 /var/www/web3/web/chat/img/table_tab.png 191214 /var/www/web3/web/chat/images/e-commerce/ameri4.jpg 186588 /var/www/web3/web/chat/images/e-commerce/ameri5.jpg 177152 /var/www/web3/web/chat/images/awards/Thumbs.db 167702 /var/www/web3/web/chat/images/e-commerce/ameri2.jpg 163989 /var/www/web3/web/chat/images/integrations/BrandonHallGrp.png OR # find /var/www/web3/web/chat/ -type f -iname "*.jpg" -printf '%s %p\n'| sort -nr | head -10 978882 /var/www/web3/web/chat/img/home/live2support_home_page.JPG 198535 /var/www/web3/web/chat/images/integrations/core5.jpg 198535 /var/www/web3/web/chat/images/e-commerce/core5.jpg 191214 /var/www/web3/web/chat/images/e-commerce/ameri4.jpg 186588 /var/www/web3/web/chat/images/e-commerce/ameri5.jpg 167702 /var/www/web3/web/chat/images/e-commerce/ameri2.jpg 156252 /var/www/web3/web/chat/images/e-commerce/big5.jpg 139324 /var/www/web3/web/chat/images/e-commerce/ameri3.jpg 138477 /var/www/web3/web/chat/images/e-commerce/simg2.jpg 129080 /var/www/web3/web/chat/images/crm/infu8.jpg

I hope this article will help you to find out the top space consuming directories and files on Linux & UNIX system. If you have any queries and problem please comment in comment section.

Источник

10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories

The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk usage of files and directories on a machine.

The du command has many parameter options that can be used to get the results in many formats. The du command also displays the files and directory sizes in a recursive manner.

Check Disk Usage In Linux

This article explains 10 useful “du” commands with their examples, which might help you to find out the sizes of files and directories in Linux. The information provided in this article is taken from the man pages of du command.

How to Find the Size of a Directory in Linux

1. To find out the disk usage summary of a /home/tecmint directory tree and each of its subdirectories. Enter the command as:

[[email protected]]# du /home/tecmint 40 /home/tecmint/downloads 4 /home/tecmint/.mozilla/plugins 4 /home/tecmint/.mozilla/extensions 12 /home/tecmint/.mozilla 12 /home/tecmint/.ssh 689112 /home/tecmint/Ubuntu-12.10 689360 /home/tecmint

The output of the above command displays the number of disk blocks in the /home/tecmint directory along with its sub-directories.

Читайте также:  Chromium установка в линукс

How to Find the Directory Size in Human Readable Format

2. Using the “-h” option with the “du” command provides results in “Human Readable Format“. This means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes, etc.

[[email protected]]# du -h /home/tecmint 40K /home/tecmint/downloads 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 12K /home/tecmint/.ssh 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint

How to Find Total Size of a Directory in Linux

3. To get the summary of a grand total disk usage size of a directory uses the option “-s” as follows.

[[email protected]]# du -sh /home/tecmint 674M /home/tecmint

4. Using the “-a” flag with the “du” command displays the disk usage of all the files and directories.

[[email protected]]# du -a /home/tecmint 4 /home/tecmint/.bash_logout 12 /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz 24 /home/tecmint/downloads/Phpfiles-org.tar.bz2 40 /home/tecmint/downloads 12 /home/tecmint/uploadprogress-1.0.3.1.tgz 4 /home/tecmint/.mozilla/plugins 4 /home/tecmint/.mozilla/extensions 12 /home/tecmint/.mozilla 4 /home/tecmint/.bashrc 689108 /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso 689112 /home/tecmint/Ubuntu-12.10 689360 /home/tecmint

5. Using the “-a” flag along with “-h” displays disk usage of all files and folders in a human-readable format. The below output is easier to understand as it shows the files in Kilobytes, Megabytes, etc.

[[email protected]]# du -ah /home/tecmint 4.0K /home/tecmint/.bash_logout 12K /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz 24K /home/tecmint/downloads/Phpfiles-org.tar.bz2 40K /home/tecmint/downloads 12K /home/tecmint/uploadprogress-1.0.3.1.tgz 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 4.0K /home/tecmint/.bashrc 673M /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint

6. Find out the disk usage of a directory tree with its subtree in Kilobyte blocks. Use the “-k” (displays size in 1024 bytes units).

[[email protected]]# du -k /home/tecmint 40 /home/tecmint/downloads 4 /home/tecmint/.mozilla/plugins 4 /home/tecmint/.mozilla/extensions 12 /home/tecmint/.mozilla 12 /home/tecmint/.ssh 689112 /home/tecmint/Ubuntu-12.10 689360 /home/tecmint

7. To get the summary of disk usage of directory tree along with its subtrees in Megabytes (MB) only. Use the option “-mh” as follows. The “-m” flag counts the blocks in MB units and “-h” stands for human-readable format.

[[email protected]]# du -mh /home/tecmint 40K /home/tecmint/downloads 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 12K /home/tecmint/.ssh 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint

8. The “-c” flag provides a grand total usage disk space at the last line. If your directory is taken 674MB space, then the last last two lines of the output would be.

[[email protected]]# du -ch /home/tecmint 40K /home/tecmint/downloads 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 12K /home/tecmint/.ssh 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint 674M total 

How to Exclude Files with du Command

9. The below command calculates and displays the disk usage of all files and directories, but excludes the files that match the given pattern. The below command excludes the “.txt” files while calculating the total size of a directory. So, this way you can exclude any file formats by using the flag “-–exclude“. See the output there is no txt files entry.

[[email protected]]# du -ah --exclude="*.txt" /home/tecmint 4.0K /home/tecmint/.bash_logout 12K /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz 24K /home/tecmint/downloads/Phpfiles-org.tar.bz2 40K /home/tecmint/downloads 12K /home/tecmint/uploadprogress-1.0.3.1.tgz 4.0K /home/tecmint/.bash_history 4.0K /home/tecmint/.bash_profile 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 4.0K /home/tecmint/.bashrc 24K /home/tecmint/Phpfiles-org.tar.bz2 4.0K /home/tecmint/geoipupdate.sh 4.0K /home/tecmint/.zshrc 120K /home/tecmint/goaccess-0.4.2.tar.gz.1 673M /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint

How to Find Directory Usage By Modification Time

10. Display the disk usage based on a modification of time, use the flag “–time” as shown below.

[[email protected]]# du -ha --time /home/tecmint 4.0K 2012-10-12 22:32 /home/tecmint/.bash_logout 12K 2013-01-19 18:48 /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz 24K 2013-01-19 18:48 /home/tecmint/downloads/Phpfiles-org.tar.bz2 40K 2013-01-19 18:48 /home/tecmint/downloads 12K 2013-01-19 18:32 /home/tecmint/uploadprogress-1.0.3.1.tgz 4.0K 2012-10-13 00:11 /home/tecmint/.bash_history 4.0K 2012-10-12 22:32 /home/tecmint/.bash_profile 0 2013-01-19 18:32 /home/tecmint/xyz.txt 0 2013-01-19 18:32 /home/tecmint/abc.txt 4.0K 2012-10-12 22:32 /home/tecmint/.mozilla/plugins 4.0K 2012-10-12 22:32 /home/tecmint/.mozilla/extensions 12K 2012-10-12 22:32 /home/tecmint/.mozilla 4.0K 2012-10-12 22:32 /home/tecmint/.bashrc 24K 2013-01-19 18:32 /home/tecmint/Phpfiles-org.tar.bz2 4.0K 2013-01-19 18:32 /home/tecmint/geoipupdate.sh 4.0K 2012-10-12 22:32 /home/tecmint/.zshrc 120K 2013-01-19 18:32 /home/tecmint/goaccess-0.4.2.tar.gz.1 673M 2013-01-19 18:51 /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso 673M 2013-01-19 18:51 /home/tecmint/Ubuntu-12.10 674M 2013-01-19 18:52 /home/tecmint

Источник

Читайте также:  Все возможности linux ubuntu

How to find and delete the top 100 most used files in Linux/Unix

Useful Queries: Query to verify the list of segments in a Greenplum system select * from gp_segment_configuration; R.

Facebook

Categories

Blog Archive

  • Best Practices
  • Big Data
  • BigData&Hadoop
  • DAG
  • Error 10294
  • external tables
  • File Formats in Hive
  • Greenplum
  • Hadoop
  • Hadoop Commands
  • Hive
  • Internal tables
  • interview Questions
  • Managed tables
  • MySQL Installation
  • ORCFILE
  • org.apache.hadoop.hive.ql.exec.MoveTask
  • Powershell
  • Problems&Solutions
  • RCFILE
  • return code 1
  • SEQUENCEFILE
  • Service ‘userhome’
  • Service ‘userhome’ check failed: java.io.FileNotFoundException
  • SQL Server
  • sqoop
  • SSIS
  • TEXTFILE
  • Tez
  • transaction manager
  • Views
  • What is Hadoop

Featured Post

TOP 100 SQL SERVER INTERVIEW QUESTIONS

SQL SERVER INTERVIEW QUESTIONS 1. What is the Complex task that you handled in your project 2. What are the diffe.

Pages

Scenarios: Deploy SSRS reports using automation #Set variables with configure values $Environment = «DEV» $rep.

Error: [DataDirect][ODBC Greenplum Wire Protocol driver][Greenplum]ERROR: Cannot parallelize an UPDATE statement that updates the distri.

Источник

Оцените статью
Adblock
detector