If we want to see what is the size occupied by folders or subfolders in linux, we can use the du
command, that is a command line utility for reporting file system disk space usage.
It can be used to find out disk usage for files or folders and to show what is taking up space and can be combined with other linux commands to output a sorted list of the largest files of folders on a system!
To view a summary of disk usage in a directory:
@ du /home/robert/app/cpu
32 /home/robert/app/cpu/auto-cpufreq/scripts
12 /home/robert/app/cpu/auto-cpufreq/bin
12 /home/robert/app/cpu/auto-cpufreq/build/scripts-3.8
32 /home/robert/app/cpu/auto-cpufreq/build/lib/source
36 /home/robert/app/cpu/auto-cpufreq/build/lib
4 /home/robert/app/cpu/auto-cpufreq/build/bdist.linux-x86_64
56 /home/robert/app/cpu/auto-cpufreq/build
8 /home/robert/app/cpu/auto-cpufreq/.github
8 /home/robert/app/cpu/auto-cpufreq/.git/info
8 /home/robert/app/cpu/auto-cpufreq/.git/logs/refs/heads
8 /home/robert/app/cpu/auto-cpufreq/.git/logs/refs/remotes/origin
12 /home/robert/app/cpu/auto-cpufreq/.git/logs/refs/remotes
24 /home/robert/app/cpu/auto-cpufreq/.git/logs/refs
32 /home/robert/app/cpu/auto-cpufreq/.git/logs
8 /home/robert/app/cpu/auto-cpufreq/.git/refs/heads
8 /home/robert/app/cpu/auto-cpufreq/.git/refs/remotes/origin
12 /home/robert/app/cpu/auto-cpufreq/.git/refs/remotes
4 /home/robert/app/cpu/auto-cpufreq/.git/refs/tags
28 /home/robert/app/cpu/auto-cpufreq/.git/refs
4 /home/robert/app/cpu/auto-cpufreq/.git/objects/info
236 /home/robert/app/cpu/auto-cpufreq/.git/objects/pack
244 /home/robert/app/cpu/auto-cpufreq/.git/objects
4 /home/robert/app/cpu/auto-cpufreq/.git/branches
56 /home/robert/app/cpu/auto-cpufreq/.git/hooks
396 /home/robert/app/cpu/auto-cpufreq/.git
24 /home/robert/app/cpu/auto-cpufreq/dist
36 /home/robert/app/cpu/auto-cpufreq/auto_cpufreq.egg-info
8 /home/robert/app/cpu/auto-cpufreq/snap
32 /home/robert/app/cpu/auto-cpufreq/source
648 /home/robert/app/cpu/auto-cpufreq
652 /home/robert/app/cpu
How to view folder disk usage in human readable format:
To view folders size in human readable format pass the -h
option:
@ du -h /home/robert/app/cpu
32K /home/robert/app/cpu/auto-cpufreq/scripts
12K /home/robert/app/cpu/auto-cpufreq/bin
12K /home/robert/app/cpu/auto-cpufreq/build/scripts-3.8
32K /home/robert/app/cpu/auto-cpufreq/build/lib/source
36K /home/robert/app/cpu/auto-cpufreq/build/lib
4.0K /home/robert/app/cpu/auto-cpufreq/build/bdist.linux-x86_64
56K /home/robert/app/cpu/auto-cpufreq/build
8.0K /home/robert/app/cpu/auto-cpufreq/.github
8.0K /home/robert/app/cpu/auto-cpufreq/.git/info
8.0K /home/robert/app/cpu/auto-cpufreq/.git/logs/refs/heads
8.0K /home/robert/app/cpu/auto-cpufreq/.git/logs/refs/remotes/origin
12K /home/robert/app/cpu/auto-cpufreq/.git/logs/refs/remotes
24K /home/robert/app/cpu/auto-cpufreq/.git/logs/refs
32K /home/robert/app/cpu/auto-cpufreq/.git/logs
8.0K /home/robert/app/cpu/auto-cpufreq/.git/refs/heads
8.0K /home/robert/app/cpu/auto-cpufreq/.git/refs/remotes/origin
12K /home/robert/app/cpu/auto-cpufreq/.git/refs/remotes
4.0K /home/robert/app/cpu/auto-cpufreq/.git/refs/tags
28K /home/robert/app/cpu/auto-cpufreq/.git/refs
4.0K /home/robert/app/cpu/auto-cpufreq/.git/objects/info
236K /home/robert/app/cpu/auto-cpufreq/.git/objects/pack
244K /home/robert/app/cpu/auto-cpufreq/.git/objects
4.0K /home/robert/app/cpu/auto-cpufreq/.git/branches
56K /home/robert/app/cpu/auto-cpufreq/.git/hooks
396K /home/robert/app/cpu/auto-cpufreq/.git
24K /home/robert/app/cpu/auto-cpufreq/dist
36K /home/robert/app/cpu/auto-cpufreq/auto_cpufreq.egg-info
8.0K /home/robert/app/cpu/auto-cpufreq/snap
32K /home/robert/app/cpu/auto-cpufreq/source
648K /home/robert/app/cpu/auto-cpufreq
652K /home/robert/app/cpu
View only the file size of a directory (without listing subfolders)
pass the -s
option to the du
command followed by the folder:
@ du -sh /home/robert/app/cpu
652K /home/robert/app/cpu
To sort folders and files by size, use sort
and the -n
(numeric) and -r
(reverse) options:
@ du -h /home/robert/app/cpu | sort -n -r
652K /home/robert/app/cpu
648K /home/robert/app/cpu/auto-cpufreq
396K /home/robert/app/cpu/auto-cpufreq/.git
244K /home/robert/app/cpu/auto-cpufreq/.git/objects
236K /home/robert/app/cpu/auto-cpufreq/.git/objects/pack
56K /home/robert/app/cpu/auto-cpufreq/.git/hooks
56K /home/robert/app/cpu/auto-cpufreq/build
36K /home/robert/app/cpu/auto-cpufreq/build/lib
36K /home/robert/app/cpu/auto-cpufreq/auto_cpufreq.egg-info
32K /home/robert/app/cpu/auto-cpufreq/source
32K /home/robert/app/cpu/auto-cpufreq/scripts
32K /home/robert/app/cpu/auto-cpufreq/.git/logs
32K /home/robert/app/cpu/auto-cpufreq/build/lib/source
28K /home/robert/app/cpu/auto-cpufreq/.git/refs
24K /home/robert/app/cpu/auto-cpufreq/.git/logs/refs
24K /home/robert/app/cpu/auto-cpufreq/dist
12K /home/robert/app/cpu/auto-cpufreq/.git/refs/remotes
12K /home/robert/app/cpu/auto-cpufreq/.git/logs/refs/remotes
12K /home/robert/app/cpu/auto-cpufreq/build/scripts-3.8
12K /home/robert/app/cpu/auto-cpufreq/bin
8.0K /home/robert/app/cpu/auto-cpufreq/snap
8.0K /home/robert/app/cpu/auto-cpufreq/.git/refs/remotes/origin
8.0K /home/robert/app/cpu/auto-cpufreq/.git/refs/heads
8.0K /home/robert/app/cpu/auto-cpufreq/.git/logs/refs/remotes/origin
8.0K /home/robert/app/cpu/auto-cpufreq/.git/logs/refs/heads
8.0K /home/robert/app/cpu/auto-cpufreq/.git/info
8.0K /home/robert/app/cpu/auto-cpufreq/.github
4.0K /home/robert/app/cpu/auto-cpufreq/.git/refs/tags
4.0K /home/robert/app/cpu/auto-cpufreq/.git/objects/info
4.0K /home/robert/app/cpu/auto-cpufreq/.git/branches
4.0K /home/robert/app/cpu/auto-cpufreq/build/bdist.linux-x86_64
Find the largest folders/subfolders on a file system
show only first 10 lines:
@ du -h /home/robert/app/cpu | sort -n -r | head -n 10
652K /home/robert/app/cpu
648K /home/robert/app/cpu/auto-cpufreq
396K /home/robert/app/cpu/auto-cpufreq/.git
244K /home/robert/app/cpu/auto-cpufreq/.git/objects
236K /home/robert/app/cpu/auto-cpufreq/.git/objects/pack
56K /home/robert/app/cpu/auto-cpufreq/.git/hooks
56K /home/robert/app/cpu/auto-cpufreq/build
36K /home/robert/app/cpu/auto-cpufreq/build/lib
36K /home/robert/app/cpu/auto-cpufreq/auto_cpufreq.egg-info
32K /home/robert/app/cpu/auto-cpufreq/source
Leave a Reply
Your email address will not be published. Required fields are marked *