Linux du Command Example | Linux show disk usage

Blogs ❯❯ Linux

Image could not load

Image on pixabay

du Command in Linux ?

Linux में du Command का use disk usage information को show करने के लिए जाता है। du Command हमें वो सभी options provide करती है जिनकी help से आप अपने system की disk usage के बारे में different - different information देख सकते हैं।

Syntax :
du [options]

du command में और भी कई सारे options available है , जिन्हे आप du --help command run करके देख सकते हैं।

$ du --help
-a, --all             write counts for all files, not just directories
    --apparent-size   print apparent sizes, rather than disk usage; although
                        the apparent size is usually smaller, it may be
                        larger due to holes in ('sparse') files, internal
                        fragmentation, indirect blocks, and the like
-B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                        '-BM' prints sizes in units of 1,048,576 bytes;
                        see SIZE format below
-b, --bytes           equivalent to '--apparent-size --block-size=1'
-c, --total           produce a grand total
-D, --dereference-args  dereference only symlinks that are listed on the
                        command line
-d, --max-depth=N     print the total for a directory (or file, with --all)
                        only if it is N or fewer levels below the command
                        line argument;  --max-depth=0 is the same as
                        --summarize
    --files0-from=F   summarize disk usage of the
                        NUL-terminated file names specified in file F;
                        if F is -, then read names from standard input
-H                    equivalent to --dereference-args (-D)
-h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
    --inodes          list inode usage information instead of block usage
-k                    like --block-size=1K
-L, --dereference     dereference all symbolic links
-l, --count-links     count sizes many times if hard linked
-m                    like --block-size=1M
-P, --no-dereference  don't follow any symbolic links (this is the default)
-S, --separate-dirs   for directories do not include size of subdirectories
    --si              like -h, but use powers of 1000 not 1024
-s, --summarize       display only a total for each argument
-t, --threshold=SIZE  exclude entries smaller than SIZE if positive

Linux du Command Examples

by default , du command आपके current directory में present सभी directories की ही disk usage information print करती है।

$ du
4       ./dir_2/d1
8       ./dir_2
4       ./dir_1/d1/d2
8       ./dir_1/d1
12      ./dir_1
4       ./dir_3
28      .

show all usage

ऊपर दिए गए example के output में सिर्फ directories का ही directory size दिखाया गया है , हालाँकि आप -a / --all option pass करके सभी files और directories का storage size print कर सकते हैं।

$ du -ah
0       ./file_1.txt
0       ./file_2.txt
4       ./dir_2/d1
8       ./dir_2
0       ./file_3.txt
4       ./dir_1/d1/d2
8       ./dir_1/d1
12      ./dir_1
4       ./dir_3
28      . 
show human readable file size

ऊपर दिए गए example में जो file size है , उससे actually आप पता नहीं लगा सकते हैं कि ये size MB है / byte है या kb में हैं। तो size को को human readable form में print करने के लिए -h option का use किया जाता है।

$ du -ah
0       ./file_1.txt
0       ./file_2.txt
4.0K    ./dir_2/d1
8.0K    ./dir_2
0       ./file_3.txt
4.0K    ./dir_1/d1/d2
8.0K    ./dir_1/d1
12K     ./dir_1
4.0K    ./dir_3
28K     .

अब आप easily समझ सकते हैं कि directories / files का size है वो KB में है। और सबसे last में total size भी print किया गया है।

show complete size of every directory

हर directory का complete size देखने के लिए आप , -c का use कर सकते हैं। नीचे दिए गए example में हर directory के size के साथ parent directory का total size भी दिखाया गया है।

$ du -ah
4       ./dir_2/d1
8       ./dir_2
4       ./dir_1/d1/d2
8       ./dir_1/d1
12      ./dir_1
4       ./dir_3
28      .
28      total

show complete size

current directory का complete size print करने के लिए -s option का use किया जाता है।

$ du -sh
28K

आप options के बाद किसी directory / file की location भी दे सकते हैं। Example के लिए ऊपर दिखाए गए अभी तक सभी examples को test directory में perform किया। हालाँकि इस directory से बाहर आकर हम test directory का path भी दे सकते हैं।

$ du -sh test
28K     test

Show size with time

files / directories के last modified time के साथ size print करने के लिए --time option का use किया जाता है।

$ du --time -h test
4.0K    2022-10-23 17:30        test/dir_2/d1
8.0K    2022-10-23 17:30        test/dir_2
4.0K    2022-10-23 17:29        test/dir_1/d1/d2
8.0K    2022-10-23 17:29        test/dir_1/d1
12K     2022-10-23 17:29        test/dir_1
4.0K    2022-10-23 17:00        test/dir_3
28K     2022-10-23 17:30        test
filter records according to size

-t option का use करके आप records को filter भी कर सकते हैं।

$ du -t 8k -h test
8.0K    test/dir_2
8.0K    test/dir_1/d1
12K     test/dir_1
28K     test

Example में , 8k का मतलब है 8kb , आप अपनी need के according इस b / g भी रख सकते हैं।

Recent Blogs

Loading ...

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook