Gadgets 4 Students Career Guide Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
304 views
in Tutorial & Interview questions by Goeduhub's Expert (9.3k points)

1 Answer

0 like 0 dislike
by Goeduhub's Expert (9.3k points)
 
Best answer

Investigate Directories For Disk Usage

Sometimes it may be required to find out which directory consuming how much disk space especially when you are used df -h and realized your available disk space is low.
du:
du command summarizes disk usage of the set of FILEs, recursively for directories.
It's often uses with -sh option:
-s, --summarize
display only a total for each argument
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
For summarizing disk usages of the files in the current directory we use:
du -sh *
Example output:
572K Documents
208M Downloads
4,0K Music
724K Pictures
4,0K Public
4,0K Templates
4,0K Videos
We can also include hidden files with using:
du -sh .[!.]* *
Example output:
6,3M .atom
4,0K .bash_history
4,0K .bash_logout
8,0K .bashrc
350M .cache
195M .config
12K .dbus
4,0K .dmrc
44K .gconf
60K .gem
520K .gimp-2.8
28K .gnome
4,0K .ICEauthority
8,3M .local
8,0K .nano
404K .nv
36K .pki
4,0K .profile
8,0K .ssh
0 .sudo_as_admin_successful
4,0K .Xauthority
4,0K .xsession-errors
4,0K .xsession-errors.old
572K Documents
208M Downloads
4,0K Music
724K Pictures
4,0K Public
4,0K Templates
4,0K Videos
Thirdly, you can add total to the output by adding ,-c, option:
du -sch .[!.]* *
Result:
...
4,0K Templates
4,0K Videos
769M total

Most importantly using du command properly on the root directory is a life saving action to find out what application/service or user is consuming your disk space wildly. For example, in case of a ridiculously low level of disk space availability for a web and mail server, the reason could be a spam attack to your mail service and you can diagnose it just by using du command.

Investigate root directory for disk usage: 

sudo du -sch /.[!.]* /*

Example output:

16K /.VolumeIcon.icns

24K /.VolumeIcon.png

13M /bin

57M /boot

4,0K /cdrom

620K /dev

13M /etc

779M /home

0 /initrd.img

406M /lib

3,9M /lib32

4,0K /lib64

16K /lost+found

4,0K /media

4,0K /mnt

367M /opt

du: cannot access '/proc/18221/task/18221/fd/4': No such file or directory

du: cannot access '/proc/18221/task/18221/fdinfo/4': No such file or directory

du: cannot access '/proc/18221/fd/4': No such file or directory

du: cannot access '/proc/18221/fdinfo/4': No such file or directory

0 /proc

20K /root

du: cannot access '/run/user/1000/gvfs': Permission denied

9,4M /run

13M /sbin

4,0K /srv

0 /sys

72K /tmp

3,5G /usr

639M /var

0 /vmlinuz

5,8G total

Lastly, the best method forms when you add a threshold size value for directories to ignore small ones. This command will only show folders with more than 1GB in size which located under root directory up to the farthermost branch of the whole directory tree in your file system: 

sudo du --threshold=1G -ch /.[!.]* /*

 Example output:

1,4G /usr/lib

1,8G /usr/share

3,5G /usr

5,8G total

Checking Disk Space

It's quite common to want to check the status of the various partitions/drives on your server/computer to see how full they are. The following command is the one you'll want to run:
df -h

This will produce output similar to the following:

[[email protected] ~]# df -h 

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

19G 1.6G 16G 9% /

tmpfs 245M 0 245M 0% /dev/shm

/dev/sda1 485M 47M 413M 11% /boot

In this basic example, we can see that the / partition only has 9% used.

For a more complex example that also covers using df to see various mountpoints, see below:

[[email protected] ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VG-root 1.9T 1.7T 89G 95% /

/dev/mapper/VG-var 431G 145G 264G 36% /var

devtmpfs 7.8G 204K 7.8G 1% /dev

tmpfs 7.8G 4.0K 7.8G 1% /dev/shm

/dev/md1 495M 126M 344M 27% /boot

ku.example.com:9421 2.5T 487G 2.0T 20% /mnt/test

tmpfs 500M 86M 415M 18% /var/ngx_pagespeed_cache 

In this example, we have a / partition that's 95% full along with an additional /var partition that's only 36% full.

It's got an external network mount of 2T that's mounted on /mnt/test and a ramdisk/tmpfs mount of 500M mounted on /var/ngx_pagespeed_cache. 

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

0 like 0 dislike
1 answer 246 views
asked Nov 2, 2019 in Tutorial & Interview questions by Goeduhub Goeduhub's Expert (9.3k points)
0 like 0 dislike
1 answer 245 views
asked Nov 2, 2019 in Tutorial & Interview questions by Goeduhub Goeduhub's Expert (9.3k points)
0 like 0 dislike
1 answer 430 views
0 like 0 dislike
1 answer 284 views
0 like 0 dislike
1 answer 260 views

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...