How to use the df command to view Linux disk space?

  
                

There are a lot of tools for viewing Linux disk space, so how do you use commands to view disk space? That will use the df command, the following small series for everyone to introduce the use of df command to view the Linux disk space.

[root @ localhost ~] # df -h

with file system capacity has been available with
mount point%

/dev /sda2 14G 11G 2.6 G 82% /

/dev/sda1 99M 14M 81M 14% /boot

tmpfs 442M 275M 168M 63% /dev/shm

/dev/mapper/vg_test- Lv_test

24M 1.3M 21M 6% /mnt/lvm

[root@localhost ~]#

Of course you may not be related to how much space the disk still has, you are Need to know the disk usage under the current folder:

[root@localhost ~]# du --max-depth=1 -h

24K . /.gnome www.2cto.com

8.0K. /.eggcups

8.0K. /.config

136K . /.gnome2

16K. /.chewing

8.0K. /.gnome2_private

8.0K. /.Trash

224K. /.gstreamer-0.10

28K. /Desktop

48K. /.nautilus

48K. /.metacity

240K. /.scim

3.4M. /.mozilla

1012K. /.kde

12K. /.superkaramba

40K. /.local

8.0K. /.qt

272K. /.gconf

32K. /.mcop

16K. /.redhat

1.7M. /.thumbnails

8.0K. /.gconfd

7.5M.

[root@localhost ~]#

See the above command using du --max-depth=1 -h to find the disk usage, because there is no path followed, it The default is the current path. The -h parameter of this command is for you to read the size of each file. If there is no file size displayed by this parameter, there is no k, M, G, etc. After executing the command, the first n-1 lines are the size of each folder in the directory. The last line shows the total size of the directory.

Then you will say that you don't care about the size of each file in the directory. You only want to know the size of one of the files (folders). Is there any way? Of course, you should remember that I have always stressed that there are always more methods than problems, and this is no exception.

Please see the following example:

[root@localhost ~]# du -sh

7.5M . Www.2cto.com

[root@localhost ~]#

You must have found that the size shown here is the same as the size of the last line above. This means that the size shown here is the total size of the directory.

I know that you are sneer in your heart, isn't the method more than the problem? There is only one answer here. Of course, I won't let you down. Another method is more soil, but it can still solve the problem.

[root@localhost ~]# du -h --max-depth=0

7.5M .

[root@localhost ~]#

What I want to tell you is that the man page has already told you that the function of --max-depth=0 is the same as the function of -s.

Of course, you can also use sed to print the last du -h --max-depth=1 line to solve the problem, but I don't recommend it.

This involves a principle, try to use the command to provide the original functionality of the option. If the command does not provide this feature, we need to use grep, sed, awk to select the rows we need.

Of course, the du command can be followed by the file path to view the size of the specified path.

[root@localhost ~]# du -sh /opt/oracle

5.6G /opt/oracle

[root@localhost ~]#

The above is the introduction of the Linux disk space using the df command. If the disk is large, it may take more time. Have you learned it?

Copyright © Windows knowledge All Rights Reserved