- 10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories
- How to Find the Size of a Directory in Linux
- How to Find the Directory Size in Human Readable Format
- How to Find Total Size of a Directory in Linux
- How to Exclude Files with du Command
- How to Find Directory Usage By Modification Time
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- Linux Check Disk Space Command To View System Disk Usage
- Linux commands to check disk space using:
- Linux check disk space with df command
- See information about specific filesystem
- Understanding df command output
- Express df output in human readable form
- Display output using inode usage instead of block usage
- Find out the type of each file system displayed
- Limit listing to file systems of given type
- Exclude given file system type
- Show all file system
- Getting more help about the df command
- Linux check disk space with the du command
- See du output in human readable format
- Finding information about any directory trees or files
- How do I summarize disk usage for given directory name?
- Putting it all together
- Dealing with btrfs file system
- Examples
- Conclusion
10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories
The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk usage of files and directories on a machine.
The du command has many parameter options that can be used to get the results in many formats. The du command also displays the files and directory sizes in a recursive manner.
Check Disk Usage of Files and Folders In Linux
This article explains 10 useful “du” commands with their examples, which might help you to find out the sizes of files and directories in Linux. The information provided in this article is taken from the man pages of du command.
Read Also:
How to Find the Size of a Directory in Linux
1. To find out the disk usage summary of a /home/tecmint directory tree and each of its subdirectories. Enter the command as:
The output of the above command displays the number of disk blocks in the /home/tecmint directory along with its sub-directories.
How to Find the Directory Size in Human Readable Format
2. Using the “-h” option with the “du” command provides results in “Human Readable Format“. This means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes, etc.
How to Find Total Size of a Directory in Linux
3. To get the summary of a grand total disk usage size of a directory uses the option “-s” as follows.
4. Using the “-a” flag with the “du” command displays the disk usage of all the files and directories.
5. Using the “-a” flag along with “-h” displays disk usage of all files and folders in a human-readable format. The below output is easier to understand as it shows the files in Kilobytes, Megabytes, etc.
6. Find out the disk usage of a directory tree with its subtree in Kilobyte blocks. Use the “-k” (displays size in 1024 bytes units).
7. To get the summary of disk usage of directory tree along with its subtrees in Megabytes (MB) only. Use the option “-mh” as follows. The “-m” flag counts the blocks in MB units and “-h” stands for human-readable format.
8. The “-c” flag provides a grand total usage disk space at the last line. If your directory is taken 674MB space, then the last last two lines of the output would be.
How to Exclude Files with du Command
9. The below command calculates and displays the disk usage of all files and directories, but excludes the files that match the given pattern. The below command excludes the “.txt” files while calculating the total size of a directory. So, this way you can exclude any file formats by using the flag “-–exclude“. See the output there is no txt files entry.
How to Find Directory Usage By Modification Time
10. Display the disk usage based on a modification of time, use the flag “–time” as shown below.
Read Also :
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
Linux Check Disk Space Command To View System Disk Usage
Linux commands to check disk space using:
- df command – Shows the amount of disk space used and available on Linux file systems.
- du command – Display the amount of disk space used by the specified files and for each subdirectory.
- btrfs fi df /device/ – Show disk space usage information for a btrfs based mount point/file system.
Linux check disk space with df command
- Open the terminal and type the following command to check disk space.
- The basic syntax for df is:
df [options] [devices]
Type: - df
- df -H
Fig.01: df command in action
See information about specific filesystem
You can give a device or mount point as an argument, and df report data only for the filesystem physically residing on that device. For example, the following command provides information only for the partition /dev/sda:
$ df /dev/sda
$ df -h /dev/sdc1
$ df /data/
Sample outputs:
Understanding df command output
The valid fields are as follows:
Display name | Valid field name (for —output option) | Description |
---|---|---|
Filesystem | source | The source of the mount point, usually a device. |
1K-blocks | size | Total number of blocks. |
Used | used | Number of used blocks. |
Available | avail | Number of available blocks. |
Use% | pcent | Percentage of USED divided by SIZE. |
Mounted on | target | The mount point. |
You can pass the output format defined by ‘valid field name’ as follows:
$ df —output=field1,field2.
$ df —output=source,used,avail /data/
Sample outputs:
You can print all available fields, enter:
$ df —o
Sample outputs:
Express df output in human readable form
Pass the -h option to see output in human readable format. You will device size in gigabytes or terabytes or megabytes:
$ df -h ### Human format
$ df -m ### Show output size in one-megabyte
$ df -k ### Show output size in one-kilobyte blocks (default)
Display output using inode usage instead of block usage
An inode is a data structure on a Linux file system that stores all information about file. To list inode information, enter:
$ df -i
$ df -i -h
Sample outputs:
Find out the type of each file system displayed
Pass the -T option to display the type of each filesystems listed such as ext4, btrfs, ext2, nfs4, fuse, cgroup, cputset, and more:
$ df -T
$ df -T -h
$ df -T -h /data/
Sample outputs:
Limit listing to file systems of given type
The syntax is:
$ df -t ext3 #Only see ext3 file system
$ df -t ext4 #Only see ext4 file system
$ df -t btrfs #Only see btrfs file system
Exclude given file system type
To list all but exclude ext2 filesystem pass the -x TYPE option, enter:
$ df -x ext2
Show all file system
Pass the -a or —all option to the df command to include in its output filesystems that have a size of zero blocks, run:
$ df -a
These file systems omitted by default.
Getting more help about the df command
Pass the —help option see a brief help message:
$ df —help
Or read its man page by typing the following command:
$ man df
Linux check disk space with the du command
The NA command is very useful to track down disk space hogs. It is useful to find out the names of directories and files that consume large amounts of space on a disk. The basic syntax is:
du
du /path/do/dir
du [options] [directories and/or files]
To see the names and space consumption of each of the directories including all subdirectories in the directory tree, enter:
$ du
Sample outputs:
The first column is expressed in kilobytes (file size) and the second column is the filename or directory name.
See du output in human readable format
Pass the -h option to display size in K (kilobytes), M (megabytes), G (gigabytes) instead of the default kilobytes:
$ du -h
Sample outputs:
Finding information about any directory trees or files
To find out /etc/ directory space usage, enter:
# du /etc/
# du -h /etc/
The following will report the sizes of the thee files named hdparm, iptunnel and ifconfig that are located in the /sbin directory:
$ du /sbin/hdparm /sbin/iptunnel /sbin/ifconfig
$ du -h /sbin/hdparm /sbin/iptunnel /sbin/ifconfig
Sample outputs:
How do I summarize disk usage for given directory name?
Pass the -s option to the du command. In this example, ask du command to report only the total disk space occupied by a directory tree and to suppress subdirectories:
# du -s /etc/
# du -sh /etc/
Sample outputs:
Pass the -a (all) option to see all files, not just directories:
# du -a /etc/
# du -a -h /etc/
Sample outputs:
You can also use star ( * ) wildcard, which will match any character. For example, to see the size of each png file in the current directory, enter:
$ du -ch *.png
The -c option tells du to display grand total.
Putting it all together
To list top 10 directories eating disk space in /etc/, enter:
# du -a /etc/ | sort -n -r | head -n 10
Sample outputs:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
For more information on the du command, type:
$ man du
$ du —help
Dealing with btrfs file system
For btrfs filesystem use the btrfs fi df command to see space usage information for a mount point. The syntax is:
Examples
# btrfs fi df /data/
# btrfs fi df -h /data/
Sample outputs:
To see raw numbers in bytes, run:
# btrfs fi df -b /data/
OR
# btrfs fi df -k /data/ ### show sizes in KiB ##
# btrfs fi df -m /data/ ### show sizes in MiB ##
# btrfs fi df -g /data/ ### show sizes in GiB ##
# btrfs fi df -t /data/ ### show sizes in TiB ##
Conclusion
Here is quick summary for Linux check disk space commands. Use the du command when you need to estimate file space usage. To report Linux file system disk space usage use the df command. The btrfs df command must be used when using btrfs file system. Fore more info see GNU coreutils page here.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
Nice article. What about “ncdu”
For graphical overview… 🙂
How do i format a 39TB drive with ext4?
web-a1
Источник