how_to_find_the_size_of_folders
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
how_to_find_the_size_of_folders [2017/01/29 18:14] – created walkeradmin | how_to_find_the_size_of_folders [2023/11/08 23:38] (current) – walkeradmin | ||
---|---|---|---|
Line 2: | Line 2: | ||
<color darkorange> | <color darkorange> | ||
\\ | \\ | ||
+ | <color red> | ||
+ | \\ | ||
+ | \\ | ||
+ | This article explains 2 simple commands that most people want to know when they | ||
+ | start using Linux. They are finding the size of a directory and finding the amount | ||
+ | of free disk space that exists on your machine. The command you would use to find | ||
+ | the directory size is du. | ||
+ | \\ | ||
+ | \\ | ||
+ | To find the free disk space you could use df. | ||
+ | \\ | ||
+ | \\ | ||
+ | All the information present in this article is available in the man pages for du and df. In case you get bored reading the man pages and you want to get your work done quickly, then this article is for you.\\ | ||
+ | \\ | ||
+ | ---- | ||
+ | ==== Better Examples ==== | ||
+ | To find the size of a directory that you are currently in | ||
+ | du -h -s | ||
+ | For example, here is the contents of my home folder: | ||
+ | < | ||
+ | drwxr-xr-x. 2 root root 90 Aug 9 11:05 nics | ||
+ | drwxr-xr-x. 3 root root 135 Nov 8 18:22 openstack | ||
+ | drwxr-xr-x. 3 root root 17 Aug 9 11:12 streamer | ||
+ | </ | ||
+ | To see the combined size of these folders, I use: | ||
+ | du -h -s | ||
+ | This gives me the output: | ||
+ | 30G . | ||
+ | Lets say I am interested in how much is in the ' | ||
+ | du -h -s * | ||
+ | This gives: | ||
+ | < | ||
+ | 12K nics | ||
+ | 1.1M openstack | ||
+ | 30G | ||
+ | </ | ||
+ | Lets use this command on the / | ||
+ | cd / | ||
+ | ll | ||
+ | drwxr-xr-x. 2 root root 128 Aug 9 11:15 1080i | ||
+ | -rw-r--r--. 1 root root 2636986136 Aug 9 11:21 avp.ts | ||
+ | drwxr-xr-x. 2 root root 44 Aug 9 11:15 bbc | ||
+ | drwxr-xr-x. 2 root root 192 Aug 9 11:18 CRa | ||
+ | drwxr-xr-x. 2 root root 67 Aug 9 11:18 example | ||
+ | drwxr-xr-x. 2 root root 63 Aug 9 11:18 itv | ||
+ | -rw-r--r--. 1 root root 87 Aug 9 11:21 kill_all_mpeg2ts_broadcaster.sh | ||
+ | -rwxr-xr-x. 1 root root | ||
+ | drwxr-xr-x. 2 root root 4096 Sep 20 15:53 MK.ts | ||
+ | -rwxr-xr-x. 1 root root 17387 Aug 9 11:21 mpeg2ts_broadcaster | ||
+ | -rw-r--r--. 1 root root 813563044 Aug 9 11:21 Oro4KTest.ts | ||
+ | drwxr-xr-x. 2 root root 105 Aug 9 11:19 virgin | ||
+ | drwxr-xr-x. 2 root root 4096 Aug 9 11:20 zb | ||
+ | Now I use the following: | ||
+ | du -h -s | ||
+ | The output is: | ||
+ | 30G . | ||
+ | However, if I use the same with a star * at the end: | ||
+ | < | ||
+ | du -h -s * | ||
+ | |||
+ | 1.3G 1080i | ||
+ | 2.5G avp.ts | ||
+ | 15G bbc | ||
+ | 502M CRa | ||
+ | 832K example | ||
+ | 576M itv | ||
+ | 4.0K kill_all_mpeg2ts_broadcaster.sh | ||
+ | 808K libos.so | ||
+ | 2.4G MK.ts | ||
+ | 20K | ||
+ | 776M Oro4KTest.ts | ||
+ | 554M virgin | ||
+ | 7.5G zb | ||
+ | </ | ||
+ | \\ | ||
+ | I could have done the same thing from say root by issuing the command: | ||
+ | < | ||
+ | du -h -s / | ||
+ | |||
+ | 1.3G / | ||
+ | 2.5G / | ||
+ | 15G / | ||
+ | 502M / | ||
+ | 832K / | ||
+ | 576M / | ||
+ | 4.0K / | ||
+ | 808K / | ||
+ | 2.4G / | ||
+ | 20K / | ||
+ | 776M / | ||
+ | 554M / | ||
+ | 7.5G / | ||
+ | </ | ||
+ | \\ | ||
+ | \\ | ||
+ | ---- | ||
+ | ==== du - Finding the size of a directory ==== | ||
+ | \\ | ||
+ | $ du | ||
+ | \\ | ||
+ | \\ | ||
+ | | ||
+ | \\ | ||
+ | $ du / | ||
+ | \\ | ||
+ | The above command would give you the directory size of the directory / | ||
+ | \\ | ||
+ | $ du -h\\ | ||
+ | \\ | ||
+ | This command gives you a better output than the default one. The option ' | ||
+ | \\ | ||
+ | $ du -ah\\ | ||
+ | \\ | ||
+ | This command would display in its output, not only the directories but also all the files that are present in the current directory. Note that ' | ||
+ | \\ | ||
+ | $ du -c <color Red>du -ch</ | ||
+ | \\ | ||
+ | This gives you a grand total as the last line of the output. So if your directory occupies 30MB the last 2 lines of the output would be\\ | ||
+ | \\ | ||
+ | 30M .\\ | ||
+ | 30M total\\ | ||
+ | \\ | ||
+ | The first line would be the default last line of the ' | ||
+ | \\ | ||
+ | $ du -ch | grep total | ||
+ | This would have only one line in its output that displays the total size of the current directory including all the subdirectories.\\ | ||
+ | \\ | ||
+ | Note : In case you are not familiar with pipes (which makes the above command possible) refer to Article No. 24 . Also grep is one of the most important commands in Unix. Refer to Article No. 25 to know more about grep.\\ | ||
+ | \\ | ||
+ | $ du -s\\ | ||
+ | This displays a summary of the directory size. It is the simplest way to know the total size of the current directory.\\ | ||
+ | \\ | ||
+ | $ du -S\\ | ||
+ | This would display the size of the current directory excluding the size of the subdirectories that exist within that directory. So it basically shows you the total size of all the files that exist in the current directory.\\ | ||
+ | \\ | ||
+ | $ du --exculde=mp3\\ | ||
+ | The above command would display the size of the current directory along with all its subdirectories, | ||
+ | \\ | ||
+ | ' | ||
+ | \\ | ||
+ | $ df\\ | ||
+ | | ||
+ | \\ | ||
+ | $ df -h\\ | ||
+ | | ||
+ | \\ | ||
+ | Most of the users don't use the other parameters that can be passed to ' | ||
+ | \\ | ||
+ | I shall in turn show you an example that I use on my machine. I have actually stored this as a script named ' | ||
+ | \\ | ||
+ | | ||
+ | \\ | ||
+ | I have my Linux installed on /dev/hda1 and I have mounted my Windows partitions as well (by default every time Linux boots). So ' | ||
+ | \\ | ||
+ | $ df -h | grep /dev/hda1 | cut -c 41-43\\ | ||
+ | \\ | ||
+ | This command displays the following on my machine\\ | ||
+ | \\ | ||
+ | 45% | ||
+ | \\ | ||
+ | | ||
+ | \\ | ||
+ | Note : In case you are not familiar with pipes (which is used in the above command) then refer to Article No. 24 . ' | ||
+ | \\ | ||
+ | There are a few more options that can be used with ' | ||
\\ | \\ |
how_to_find_the_size_of_folders.1485713691.txt.gz · Last modified: 2023/03/09 22:35 (external edit)