What functions of the df command you don't know under Linux
Feb 14, 2024 pm 09:39 PMQuestion: I want to use the df command on Linux to check the disk usage space. Can you give me some specific examples of the df command so I can make better use of it?
On Linux, if you want to know how much space a specific file system takes up, or how much space is available for a specific file system, you can use the df command. The df command is a command that displays the available disk space of the file system for each filename parameter. If you do not specify any file names, the output will show the available space for all currently mounted file systems. By default, df displays disk space in 1K blocks.
Linux has many command line or graphical interface tools that can tell you detailed information about current disk space usage, such as a simple overview, detailed statistics or intuitive graphical reports. But if you just want to know the remaining disk space of different file systems, then the df command may be what you need.

The df command can display the disk utilization of any "mounted" file system. This command can be called in different ways. Here are some useful df command examples.
Present in a way that people can read
By default, the df command uses 1K blocks to display disk space, which does not seem very intuitive. The "-h" parameter makes df print the disk space in a more readable way (such as 100K, 200M, 3G).
“
$?df?-h”
“
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu-root 909G 565G 299G 66% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 3.9G 4.0K 3.9G 1% /dev
tmpfs 785M 1.2M 784M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 3.9G 63M 3.8G 2% /run/shm
none 100M 48K 100M 1% /run/user
/dev/sda1 228M 98M 118M 46% /boot
?”
Show Inode usage
When you monitor disk usage, you must pay attention to not only disk space but also "inode" usage. In Linux, an inode is a data structure used to store metadata for a specific file. When a file system is created, a predefined number of inodes are allocated. This means that a file system can run out of space not just because large files use up all available space, but also because many small files use up all possible inodes. Use the "-i" option to display inode usage.
“
$?df?-i”
“
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/ubuntu-root 60514304 1217535 59296769 3% /
none 1004417 13 1004404 1% /sys/fs/cgroup
udev 1000623 552 1000071 1% /dev
tmpfs 1004417 608 1003809 1% /run
none 1004417 11 1004406 1% /run/lock
none 1004417 288 1004129 1% /run/shm
none 1004417 28 1004389 1% /run/user
/dev/sda1 124496 346 124150 1% /boot
”
展示磁盤總利用率
默認(rèn)情況下, df命令顯示磁盤的單個(gè)文件系統(tǒng)的利用率。如果你想知道的所有文件系統(tǒng)的總磁盤使用量,增加“ –total ”選項(xiàng)(見最下面的匯總行)。
“
$?df?-h?--total”
“
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu-root 909G 565G 299G 66% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 3.9G 4.0K 3.9G 1% /dev
tmpfs 785M 1.2M 784M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 3.9G 62M 3.8G 2% /run/shm
none 100M 48K 100M 1% /run/user
/dev/sda1 228M 98M 118M 46% /boot
total 918G 565G 307G 65% –
”
展示文件系統(tǒng)類型
默認(rèn)情況下,df命令不顯示文件系統(tǒng)類型信息。用“-T”選項(xiàng)來添加文件系統(tǒng)信息到輸出中。
“
$?df?-T”
“
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/ubuntu-root ext4 952893348 591583292 312882844 66% /
none tmpfs 4 0 4 0% /sys/fs/cgroup
udev devtmpfs 4002492 4 4002488 1% /dev
tmpfs tmpfs 803536 1196 802340 1% /run
none tmpfs 5120 0 5120 0% /run/lock
none tmpfs 4017668 60176 3957492 2% /run/shm
none tmpfs 102400 48 102352 1% /run/user
/dev/sda1 ext2 233191 100025 120725 46% /boot
”
包含或排除特定的文件系統(tǒng)類型
如果你想知道特定文件系統(tǒng)類型的剩余空間,用“-t ”選項(xiàng)。你可以多次使用這個(gè)選項(xiàng)來包含更多的文件系統(tǒng)類型。
“
$?df?-t?ext2?-t?ext4”
“
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/ubuntu-root 952893348 591583380 312882756 66% /
/dev/sda1 233191 100025 120725 46% /boot
”
排除特定的文件系統(tǒng)類型,用“-x ”選項(xiàng)。同樣,你可以用這個(gè)選項(xiàng)多次來排除多種文件系統(tǒng)類型。
“
$?df?-x?tmpfs”
顯示一個(gè)具體的掛載點(diǎn)磁盤使用情況
如果你用df指定一個(gè)掛載點(diǎn),它將報(bào)告掛載在那個(gè)地方的文件系統(tǒng)的磁盤使用情況。如果你指定一個(gè)普通文件(或一個(gè)目錄)而不是一個(gè)掛載點(diǎn),df將顯示包含這個(gè)文件(或目錄)的文件系統(tǒng)的磁盤利用率。
“
$?df?/”
“
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/ubuntu-root 952893348 591583528 312882608 66% /
”
“
$?df?/home/dev”
“
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/ubuntu-root 952893348 591583528 312882608 66% /
”
顯示虛擬文件系統(tǒng)的信息
如果你想顯示所有已經(jīng)存在的文件系統(tǒng)(包括虛擬文件系統(tǒng))的磁盤空間信息,用“-a”選項(xiàng)。這里,虛擬文件系統(tǒng)是指沒有相對應(yīng)的物理設(shè)備的假文件系統(tǒng),例如,tmpfs,cgroup虛擬文件系統(tǒng)或FUSE文件安系統(tǒng)。這些虛擬文件系統(tǒng)大小為0,不用“-a”選項(xiàng)將不會被報(bào)告出來。
“
$?df?-a”
“
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/ubuntu-root 952893348 591578716 312887420 66% /
proc 0 0 0 – /proc
sysfs 0 0 0 – /sys
none 4 0 4 0% /sys/fs/cgroup
none 0 0 0 – /sys/fs/fuse/connections
none 0 0 0 – /sys/kernel/debug
none 0 0 0 – /sys/kernel/security
udev 4002492 4 4002488 1% /dev
devpts 0 0 0 – /dev/pts
tmpfs 803536 1196 802340 1% /run
none 5120 0 5120 0% /run/lock
none 4017668 58144 3959524 2% /run/shm
none 102400 48 102352 1% /run/user
none 0 0 0 – /sys/fs/pstore
cgroup 0 0 0 – /sys/fs/cgroup/cpuset
cgroup 0 0 0 – /sys/fs/cgroup/hugetlb
/dev/sda1 233191 100025 120725 46% /boot
vmware-vmblock 0 0 0 – /run/vmblock-fuse
”
The above is the detailed content of What functions of the df command you don't know under Linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

The key to installing dual systems in Linux and Windows is partitioning and boot settings. 1. Preparation includes backing up data and compressing existing partitions to make space; 2. Use Ventoy or Rufus to make Linux boot USB disk, recommend Ubuntu; 3. Select "Coexist with other systems" or manually partition during installation (/at least 20GB, /home remaining space, swap optional); 4. Check the installation of third-party drivers to avoid hardware problems; 5. If you do not enter the Grub boot menu after installation, you can use boot-repair to repair the boot or adjust the BIOS startup sequence. As long as the steps are clear and the operation is done properly, the whole process is not complicated.

ToinstallRedisonaLinuxsystem,followthesesteps:1)DownloadandextractRedisfromtheofficialGitHubrepository,2)CompileRedisusingthe'make'command,3)InstallRediswith'sudomakeinstall',4)ConfigureRedisbycopyingandeditingtheconfigurationfile,and5)StartRedisusin

The key to enabling EPEL repository is to select the correct installation method according to the system version. First, confirm the system type and version, and use the command cat/etc/os-release to obtain information; second, enable EPEL through dnfinstallepel-release on CentOS/RockyLinux, and the 8 and 9 version commands are the same; third, you need to manually download the corresponding version of the .repo file and install it on RHEL; fourth, you can re-import the GPG key when encountering problems. Note that the old version may not be supported, and you can also consider enabling epel-next to obtain the test package. After completing the above steps, use dnfrepolist to verify that the EPEL repository is successfully added.

Newbie users should first clarify their usage requirements when choosing a Linux distribution. 1. Choose Ubuntu or LinuxMint for daily use; programming and development are suitable for Manjaro or Fedora; use Lubuntu and other lightweight systems for old devices; recommend CentOSStream or Debian to learn the underlying principles. 2. Stability is preferred for UbuntuLTS or Debian; you can choose Arch or Manjaro to pursue new features. 3. In terms of community support, Ubuntu and LinuxMint are rich in resources, and Arch documents are technically oriented. 4. In terms of installation difficulty, Ubuntu and LinuxMint are relatively simple, and Arch is suitable for those with basic needs. It is recommended to try it first and then decide.

The steps to add a new hard disk to the Linux system are as follows: 1. Confirm that the hard disk is recognized and use lsblk or fdisk-l to check; 2. Use fdisk or parted partitions, such as fdisk/dev/sdb and create and save; 3. Format the partition to a file system, such as mkfs.ext4/dev/sdb1; 4. Use the mount command for temporary mounts, such as mount/dev/sdb1/mnt/data; 5. Modify /etc/fstab to achieve automatic mount on the computer, and test the mount first to ensure correctness. Be sure to confirm data security before operation to avoid hardware connection problems.

Logs in Linux systems are usually stored in the /var/log directory, which contains a variety of key log files, such as syslog or messages (record system logs), auth.log (record authentication events), kern.log (record kernel messages), dpkg.log or yum.log (record package operations), boot.log (record startup information); log content can be viewed through cat, tail-f or journalctl commands; application logs are often located in subdirectories under /var/log, such as Apache's apache2 or httpd directory, MySQL log files, etc.; at the same time, it is necessary to note that log permissions usually require s

Have problems uploading files in Google Chrome? This may be annoying, right? Whether you are attaching documents to emails, sharing images on social media, or submitting important files for work or school, a smooth file upload process is crucial. So, it can be frustrating if your file uploads continue to fail in Chrome on Windows PC. If you're not ready to give up your favorite browser, here are some tips for fixes that can't upload files on Windows Google Chrome 1. Start with Universal Repair Before we learn about any advanced troubleshooting tips, it's best to try some of the basic solutions mentioned below. Troubleshooting Internet connection issues: Internet connection

sudo stands for "substituteuserdo" or "superuserdo", allowing users to run commands with permissions of other users (usually root). Its core uses include: 1. Perform system-level operations such as installing software or editing system files; 2. Accessing protected directories or logs; 3. Manage services such as restarting nginx; 4. Modify global settings such as /etc/hosts. When using it, the system will check the /etc/sudoers configuration and verify the user password, provide temporary permissions instead of continuously logging in as root, ensuring security. Best practices include: only when necessary, avoid blindly executing network commands, editing sudoers files with visudo, and considering continuous operations.
