linux view disk space size command

  • 2020-05-14 05:48:20
  • OfStack

Ubuntu views file and disk space size management

(1) view file size

View all file sizes (including subfolders) in the current folder


du -sh

# du -h
15M   ./package
16K   ./.fontconfig
4.0K  ./.cache
5.1M  ./.rpmdb
20M   .

View all file sizes (including subfolders) in the specified folder


# du -h ftp
3.8G  ftp/sanya/doc
3.8G  ftp/sanya
4.0K  ftp/testftp/doc
1.4M  ftp/testftp
875M  ftp/platform/doc/002- video 
27M   ftp/platform/doc/001-PDF
5.2M  ftp/platform/doc/BBFlash
1.2G  ftp/platform/doc/003- The recording 
2.1G  ftp/platform/doc
2.1G  ftp/platform
4.0K  ftp/pmo/doc
20K   ftp/pmo
36M   ftp/uf/doc/innovate-201207
36M   ftp/uf/doc
36M   ftp/uf
446M  ftp/code/doc
446M  ftp/code
6.3G  ftp

View the specified file size


# du -h ./package/compat-libstdc++-33-3.2.3-69.el6.x86_64.rpm 
184K  ./package/compat-libstdc++-33-3.2.3-69.el6.x86_64.rpm

View the specified folder size


# du -hs ftp
6.3G  ftp

Usage: du... [file]...

Or: du... - files0 - from = F

Calculate the disk usage for each file, and the directory takes the total usage.

The parameters that long options must use are also required for short options.

-a, --all outputs disk usage for all files, not just directories

-- apparent-size shows surface usage, not disk usage; Although the surface usage is usually 1 less, it can sometimes become larger due to "holes" between sparse files, internal fragments, non-directly referenced blocks, and so on.

-B, -- block-size = size a block with a specified number of bytes

Minus b, --bytes is equal to -- apparent-size -- block-size is equal to 1

-c, --total displays the total information

-D, -- dereference-args unjoins the symbols listed on the command line

-- files0-from =F calculates the disk space consumed by the file names ending in NUL in the file F. If the value of F is "-", the file name is read from standard input

-H is equal to -- dereference-args (-D)

-h, -- human-readable displays dimensions in a readable manner (e.g., 1K 234M 2G)

--si is similar to -h, but USES 1000 as the base instead of 1024

- k equals - K block - size = 1

-l, -- count-links if it is hardwired, size it multiple times

- m equals - M block - size = 1

-L, --dereference finds the real destination indicated by any symbolic link

-P, -- no-dereference does not follow any symbolic links (default)

-0, --null treats each blank line as a 0 byte rather than a newline character

-S, -- separate-dirs does not include subdirectory occupancy

-s, --summarize only calculates the total consumption of each parameter in the command line separately

-x, -- one-file-system skips directories on different file systems

-X, -- exclude-from = files exclude files that match the schema described in the specified file

--exclude=PATTERN excludes files that match the schema described in PATTERN

-- max-depth =N displays directory totals (with --all 1 using calculated files). When N is the specified value, the calculation depth is N;

- max - depth = 0 equals - summarize

--time displays the last modified time of all files in a directory or subdirectory of that directory

--time=WORD shows the WORD time, not the modified time: atime, access, use, ctime or status

-- time-style = style display time according to the specified style (the style interpretation rule is the same as the "date" command) : full-iso, long-iso, iso, +FORMAT

--help displays this help and exits

--version displays version information and exits [size] in the following units (integers can be added before units) : kB 1000, K 1024, MB 1000000, M 1048576, G, T, P, E, Z, Y.

Please report the error to du

GNU coreutils project home page: < http://www.gnu.org/software/coreutils/ >

GNU software 1 general help: < http://www.gnu.org/gethelp/ >

Please refer to < http://translationproject.org/team/zh_CN.html > Report an du translation error

(2) Ubuntu view disk space size command

df-h Df command: linux system view file system by disk partition, you can add parameters to view the remaining disk space information, command format: df-hl display format: File system capacity available used % hardpoint Filesystem Size Used Use% Mounted on /dev/hda2 45G 24G 44% / /dev/hda1 494


df  -h

The Df command is to view the file system with the disk partition as the unit. You can add parameters to view the remaining disk space information. The command format is:


df -hl

The display format is:

File system capacity used available used % mount point

Filesystem Size Used Avail Use% Mounted on

/dev/hda2 45G 19G 24G 44% /

/dev/hda1 494M 19M 450M 4% /boot

/dev/hda6 4.9G 2.2G 2.5G 47% /home

/dev/hda5 9.7G 2.9G 6.4G 31% /opt

none 1009M 0 1009M 0% /dev/shm

/dev/hda3 9.7G 7.2G 2.1G 78% /usr/local

/dev/hdb2 75G 75G 0 100% /

/dev/hdb2 75G 75G 0 100% /

The above output is taken as an example, which means:

The second hard disk of the HD hard disk interface (b), the second partition (2), has a capacity of 75G, USES 75G, can be 0, so the utilization is 100%, and is mounted to the root partition directory (/).

Here is an explanation of the command:

df-hl view the remaining disk space

df-h looks at the partition size for each root path

du-sh [directory name] returns the size of the directory

du-sm [folder] returns the total number of M for that folder

More functions can be viewed by typing 1:


df --help
du --help

(3) delete log files

Today, 1 saw that nothing was put on the company's linux server, but it has been used for 50%. 1 checked that the log file was too big, so I deleted it manually.

This one is faster


sudo /dev/null > /var/log/**.log

The following one is recommended


sudo find /var/log/ -type f -mtime +30 -exec rm -f {} \;

Delete old files 30 days old


Related articles: