Description of commands for viewing disk information in Linux
I. df
1. Introduction
df, short for disk free, has been a part of UNIX and Unix-like operating systems since their early days. It is designed as a tool to monitor the amount of disk space used and available on your system.
The df command is used to check the amount of used and available disk space on the file system. This is especially important when managing server systems, where running out of disk space can cause serious problems.
If no file name is specified, the space available on all currently mounted file systems is displayed. Spaces are displayed in 1K blocks by default, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
The amount displayed is in bytes by default.
principle
Command to retrieve disk information from /proc/mounts or /etc/mtab.
2. Common options
-a, --all
: includes pseudo-(pseudo-file systems with 0 blocks (not directly bound to a physical device), duplicate, and inaccessible file systems.
df -a
-h, --human-readable
: Print in a human-readable manner, such as: KB, MB, GB, print size in 1024 units.
df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 863M 0 863M 0% /dev tmpfs 893M 168K 893M 1% /dev/shm tmpfs 893M 9.5M 883M 2% /run tmpfs 893M 0 893M 0% /sys/fs/cgroup /dev/map[...] 17G 6.9G 11G 41% / /dev/sda1 1014M 255M 760M 26% /boot tmpfs 179M 120K 179M 1% /run/user/1000
-H, --si
: Similar to -h, the print size is in 1000 units.
df -H
-k
: Displays all mounted file system information and usage in 1024-byte blocks, with kilobytes (kb) as the size.
df -k
-m
: Displays size in megabytes
df -m
-i, --inodes
: Lists inode information instead of block usage.
Inodes are data structures that store file and directory information, such as ownership, permissions, and timestamps.
df -i Filesystem Inodes IUsed IFree IUse% Mounted on devtmpfs 216K 393 216K 1% /dev tmpfs 224K 3 224K 1% /dev/shm tmpfs 224K 857 223K 1% /run tmpfs 224K 17 224K 1% /sys/fs/cgroup /dev/map[...] 8.5M 168K 8.4M 2% / /dev/sda1 512K 310 512K 1% /boot tmpfs 224K 74 224K 1% /run/user/1000
Node information field description:
Filesystem: Filesystem name Inodes: the total number of inodes on the file system IUsed: the number of unused inodes IFree: the number of unused inodes IUse% : The percentage of used inodes Mounted on: the directory where the file system is mounted
-l, --local
: Limits output to the local file system.
df -l
--output[=FIELD_LIST]
: Customize the output field.
df -h --output=source,avail,pcent,target Filesystem Avail Use% Mounted on devtmpfs 863M 0% /dev tmpfs 893M 1% /dev/shm tmpfs 883M 2% /run tmpfs 893M 0% /sys/fs/cgroup /dev/map[...] 11G 41% / /dev/sda1 760M 26% /boot tmpfs 179M 1% /run/user/1000
-P, --portability
: Uses POSIX output format
df -P
--total
: Delete all items that are not important to the available space and sum the total statistics.
df -h --total Filesystem Size Used Avail Use% Mounted on devtmpfs 863M 0 863M 0% /dev tmpfs 893M 168K 893M 1% /dev/shm tmpfs 893M 9.5M 883M 2% /run tmpfs 893M 0 893M 0% /sys/fs/cgroup /dev/map[...] 17G 6.9G 11G 41% / /dev/sda1 1014M 255M 760M 26% /boot tmpfs 179M 120K 179M 1% /run/user/1000 total 22G 7.2G 15G 33% -
-t, --type=[TYPE]
: Lists only information about the specified file system type.
df -t ext4 Filesystem 1K-blocks Used Available Use% Mounted on /dev/nvme0n1p3 222284728 183666112 27257432 88% / /dev/sda1 480588496 172832632 283320260 38% /data
-T, --print-type
: Prints the file system type
df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sda1 ext4 102384432 45735432 51335636 47% / tmpfs tmpfs 4145120 4 4145116 1% /dev/shm
-x, --exclude-type=[TYPE]
: Excludes the specified file system type
df -x tmpfs
--help: Displays the help information
--version: Displays the version information
3. Example commands
- Common usage
df Filesystem 1K-blocks Used Available Use% Mounted on dev 8172848 0 8172848 0% /dev run 8218640 1696 8216944 1% /run /dev/nvme0n1p3 222284728 183057872 27865672 87% / tmpfs 8218640 150256 8068384 2% /dev/shm tmpfs 8218640 0 8218640 0% /sys/fs/cgroup tmpfs 8218640 24 8218616 1% /tmp /dev/nvme0n1p1 523248 107912 415336 21% /boot /dev/sda1 480588496 172832632 283320260 38% /data tmpfs 1643728 40 1643688 1% /run/user/1000
Output field description:
Filesystem: Name of a file system 1k-blocks: size of a file system (in 1K blocks) Used: Used space in 1K blocks Available: available space in 1K blocks Use% : percentage of used space Mounted on: Directory to which the file system is mounted
- df and grep together print only the total amount of space
df -h --total|grep ^total total 22G 7.2G 15G 33% -
- Prints the space usage for the specified mount point
df -h/Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-stream 17G 6.9G 11G 41% / df -h /boot Filesystem Size Used Avail Use% Mounted on /dev/sda1 1014M 255M 760M 26% /boot
- Specify the file name and view information about the mount point where the file name resides
df -h abc.txt
- df combined sort is sorted by usage size
df --output=size,target | sort -n -r Size Mounted on 98G / 4.0G /dev/shm
4. Output the format field
source: indicates the source of the file system
fstype: indicates the type of the file system
itotal: indicates the total number of inodes
iused: indicates the number of inodes that have been used
iavail: indicates the number of available index nodes
ipcent: percentage of used inodes
size: total disk space
used: indicates the used disk space
avail: indicates the available disk space
pcent: percentage of used disk space
file: Specifies the file name on the command line
target: The directory to which the file system is mounted
5.man pages
Ii. du
1. Introduction
du, short for disk usage, has been a part of UNIX and Unix-like systems since the early days. It is designed to provide a summary of disk usage of the directory tree (including its subdirectories).
The du command is used to know the disk space used by directories or files on the system. It's especially handy when trying to identify large files or directories that take up most of your disk space.
2. Common options
-0, --null
: Ends each output line with NUL instead of line feed.
du -0
-a, --all
: Displays disk usage for each individual file, not just directories.
du -a
-B, --block-size=[SIZE]
: Print the specified size format
du --block-size=1M
--apparent-size
The file size of the print surface, not the disk usage, although the surface file size may be small, but because of the file size increase there may be some internal fragmentation in the file, actually occupy a larger disk.
du --apparent-size
-c, --total
: Provides a total of disk usage.
du -c /home/abc/article_submissions/ 12K /home/abc/article_submissions/my_articles 36K /home/abc/article_submissions/community_content 48K /home/abc/article_submissions/ 48K total
-d, --max-depth=N
: Specifies the depth of the recursion
du --max-depth=1
-h, --human-readable
: Print in human-readable units
du -h 64K ./test_dir 128K .
--inodes
: Lists inode usage, not block usage
du --inodes
-k
: The value is displayed in KB
du -k is equal to: du --block-size=1K
-m
: Output in MB(megabytes)
du -m is equal to: du --block-size=1M
-S, --separate-dirs
: does not contain the subdirectory size
du -S
--si
: similar to-h
, using powers of 1000 instead of 1024
du --si
-s, --summarize
: Displays only the total number of each parameter
du -s
--time
: Displays the last modification time of all files in a directory or subdirectory of the directory
du --time
--time=[WORD]
: Displays the specified time format instead of the default modification time, for example: atime, access, use, ctime, status
du --time=atime
-x, --exclude-from=[FILE] : excludes files matching any pattern in [FILE]
--exclude=[PATTERN] : excludes matched files
du -ah --exclude="*.dll"
PATTERN is a shell pattern (not a regular expression). A pattern? Matches any character, and * matches any string (consisting of zero, one, or more characters). For example :*.o will match any file ending in.o. Therefore, the command du --exclude='*.o' will skip all files and subdirectories ending in.o (including the *.o file itself).
-x, --one-file-system
: Skips directories on different file systems
du -x
--help
: Print help information
du --help
--version
: Prints version information
du --version
3. Example commands
-h
Access to specified directory
du -h /home/user/documents
--exclude
Access to specified directory
du -h --exclude='*.txt' /home/user/documents
- Used in conjunction with the sort command, sort by file usage
du -h --max-depth=1 | sort -hr 128K . 64K ./test_dir
- Prints the total usage of all files in the current directory
du -sh .
4.man pages
The above is the Linux view disk information command detailed content, more information about Linux view disk information please pay attention to script home other related articles!
- How do I view Raid array information in linux
- linux uses the dd command to view the server disk I/O performance
- Description of commands for viewing disk space in linux
- Linux Ubuntu implements checking the free disk space and memory
- Linux looks at disk IO and identifies processes that are high IO read/write users
Related article
-
Learn more commands of a Linux command every day
more command, function is similar to cat, more will be displayed page by page to facilitate the user to read page by page, and the most basic command is to press the blank key (space) to display the next page, press the b key will be back (back) page display, and there is a search string function2016-12-12 -
linux rights management command script parsing
This article mainly introduces the linux rights management command script analysis, friends in need can use for reference, I hope to be helpful, I wish you a lot of progress, early promotion and pay rise2023-09-09 -
Shell script to delete a year ago file function sharing
This article mainly introduces the Shell script to delete a year ago file function sharing, this article directly gives the implementation code, need friends can refer to2014-12-12 -
Clever use of the source command in the shell
This article mainly introduces the clever use of the source command in the shell. This article gives you a very detailed introduction, which has certain reference value for your study or work. You can refer to it if you need it2017-11-11 -
This command is used to query the sed command of system logs from a certain period to the present
View the sed command of the system log from a certain period to the present, and you can refer to it2013-02-02 -
Description of the function of @echo off
This article mainly introduces the role of @echo off in detail, the article introduces very detailed through the example code, which has certain reference value for everyone's study or work, and the friends who need to study together with the small series below2023-05-05 -
Shell script methods to avoid repeated execution
This article mainly introduces the method of Shell script to avoid repeated execution, the code given in this article can avoid repeated execution as long as it is placed in the head of the script to be executed, which is very convenient and practical, and the friends in need can refer to it2015-01-01 -
Summary of remote SSH connection service and basic troubleshooting experience
The following Xiaobian will bring you a summary of remote SSH connection services and basic debugging experience. Xiaobian think it is good to listen to, now I will share it with you, and also give you a reference. Let's take a look2017-04-04 -
ssh expect script code for automatic login
ssh remote login, each time to specify a bunch of user names and passwords, now requires automatic login2013-02-02 -
This section describes the Linux top command
The top command is a commonly used performance analysis tool under Linux, which can display the resource occupancy of each process in the system in real time, similar to the Windows task manager, this article mainly introduces the detailed explanation of the Linux top command, including the use of the top command, the need of friends can refer to the next2022-10-10
Latest comments