目次
Understanding df and du Commands in Linux
1. df Command
1.1. df Command Examples
2. du Command
2.1. du Command Examples
Difference between df and du Commands
Frequently Asked Questions
Conclusion
ホームページ システムチュートリアル Linux ディスクスペース分析は簡単になりました:LinuxでDFとDUコマンドを理解する

ディスクスペース分析は簡単になりました:LinuxでDFとDUコマンドを理解する

Mar 23, 2025 am 09:55 AM

Disk Space Analysis Made Easy: Understanding df And du Commands In Linux

If you're new to the Linux environment, it's common to feel puzzled by certain commands, especially when they serve similar purposes. One such confusion arises between the df and du commands, both of which are used for disk space analysis. Don't worry, you're not alone! Understanding df and du commands and their distinct purposes is key to effectively managing your disk space in Linux. In this beginner-friendly guide, we will demystify the df and du commands, helping you gain clarity on their functionalities and how they contribute to analyzing disk space in Linux. By the end of this article, you'll feel confident in distinguishing between these commands and utilizing them to make informed decisions about your disk space management.

Table of Contents

Understanding df and du Commands in Linux

The df and du commands are both used for disk space analysis in Linux, but they serve different purposes. First, we will discuss about df command.

1. df Command

The df command stands for "disk free" and is used to display information about file system disk space usage. It provides an overview of available, used, and total disk space on mounted file systems. It helps you understand how much space is used and how much is available on each partition or file system.

Example:

$ df -h
ログイン後にコピー
ログイン後にコピー

Explanation:

The command displays disk space usage in a human-readable format (-h), providing information about file systems, their total size, used space, available space, and utilization percentage.

1.1. df Command Examples

Here are some examples of using the df command along with their explanations:

1. Basic Disk Space Usage:

$ df
ログイン後にコピー

Sample Output:

Filesystem     1K-blocks      Used Available Use% Mounted on
udev            16191444         0  16191444   0% /dev
tmpfs            3248044      1936   3246108   1% /run
/dev/nvme0n1p2 478096136 186495704 267241008  42% /
tmpfs           16240220     25348  16214872   1% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
/dev/nvme0n1p1    523248      3484    519764   1% /boot/efi
/dev/sda1      976698752 389951104 586747648  40% /media/ostechnix/SK_WD_SSD
/dev/fuse         131072        20    131052   1% /etc/pve
tmpfs            3248044      1644   3246400   1% /run/user/1000
ログイン後にコピー

Explanation:

Running df without any options displays disk space usage for all mounted file systems. It shows information such as file system, total size, used space, available space, and the mount point.

2. Human-Readable Output:

$ df -h
ログイン後にコピー
ログイン後にコピー

Sample Output:

Filesystem      Size  Used Avail Use% Mounted on
udev             16G     0   16G   0% /dev
tmpfs           3.1G  1.9M  3.1G   1% /run
/dev/nvme0n1p2  456G  178G  255G  42% /
tmpfs            16G   25M   16G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/nvme0n1p1  511M  3.5M  508M   1% /boot/efi
/dev/sda1       932G  372G  560G  40% /media/ostechnix/SK_WD_SSD
/dev/fuse       128M   20K  128M   1% /etc/pve
tmpfs           3.1G  1.7M  3.1G   1% /run/user/1000
ログイン後にコピー

Explanation:

Adding the -h option makes the output human-readable, displaying sizes in a more understandable format (e.g., KB, MB, GB).

3. Specific File System:

$ df /dev/sda1
ログイン後にコピー

Sample Output:

Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda1      976698752 389951104 586747648  40% /media/ostechnix/SK_WD_SSD
ログイン後にコピー

Explanation:

Specifying a file system, such as /dev/sda1, shows disk space usage specifically for that file system.

4. Multiple File Systems:

$ df /dev/sda1 /dev/sdb1
ログイン後にコピー

Explanation:

You can provide multiple file system paths as arguments to the df command to see the disk space usage for each of them.

5. Inode Usage:

$ df -i
ログイン後にコピー

Sample Output:

Filesystem       Inodes   IUsed    IFree IUse% Mounted on
udev            4047861     617  4047244    1% /dev
tmpfs           4060055    1122  4058933    1% /run
/dev/nvme0n1p2 30433280 1402561 29030719    5% /
tmpfs           4060055      61  4059994    1% /dev/shm
tmpfs           4060055      14  4060041    1% /run/lock
/dev/nvme0n1p1        0       0        0     - /boot/efi
/dev/sda1             0       0        0     - /media/ostechnix/SK_WD_SSD
/dev/fuse        262144      37   262107    1% /etc/pve
tmpfs            812011     104   811907    1% /run/user/1000
ログイン後にコピー

Explanation:

Using the -i option displays the inode usage, which shows information about the number of used and available inodes on each file system.

6. Display File System Type:

$ df -T
ログイン後にコピー

Sample Output:

Filesystem     <strong><mark>Type</mark></strong>     1K-blocks      Used Available Use% Mounted on
udev           <strong><mark>devtmpfs</mark></strong>  16191444         0  16191444   0% /dev
tmpfs          <strong><mark>tmpfs</mark></strong>      3248044      1936   3246108   1% /run
/dev/nvme0n1p2 <strong><mark>ext4</mark></strong>     478096136 186495792 267240920  42% /
tmpfs          <strong><mark>tmpfs</mark></strong>     16240220     25348  16214872   1% /dev/shm
tmpfs          <strong><mark>tmpfs</mark></strong>         5120         4      5116   1% /run/lock
/dev/nvme0n1p1 <strong><mark>vfat</mark></strong>        523248      3484    519764   1% /boot/efi
/dev/sda1      <strong><mark>exfat</mark></strong>    976698752 389951104 586747648  40% /media/ostechnix/SK_WD_SSD
/dev/fuse      <strong><mark>fuse</mark></strong>        131072        20    131052   1% /etc/pve
tmpfs          <strong><mark>tmpfs</mark></strong>      3248044      1644   3246400   1% /run/user/1000
ログイン後にコピー

Explanation:

Adding the -T option shows the file system type along with disk space usage information.

7. Exclude Pseudo File Systems:

$ df -x tmpfs -x devtmpfs
ログイン後にコピー

Sample Output:

Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/nvme0n1p2 478096136 186495884 267240828  42% /
/dev/nvme0n1p1    523248      3484    519764   1% /boot/efi
/dev/sda1      976698752 389951104 586747648  40% /media/ostechnix/SK_WD_SSD
/dev/fuse         131072        20    131052   1% /etc/pve
ログイン後にコピー

Explanation:

The -x option followed by one or more file system types excludes them from the output. In this example, we exclude the tmpfs and devtmpfs file systems.

8. Display File System inodes and Blocks:

$ df -i -B M
ログイン後にコピー

Sample Output:

Filesystem       Inodes   IUsed    IFree IUse% Mounted on
udev            4047861     617  4047244    1% /dev
tmpfs           4060055    1122  4058933    1% /run
/dev/nvme0n1p2 30433280 1402573 29030707    5% /
tmpfs           4060055      61  4059994    1% /dev/shm
tmpfs           4060055      14  4060041    1% /run/lock
/dev/nvme0n1p1        0       0        0     - /boot/efi
/dev/sda1             0       0        0     - /media/ostechnix/SK_WD_SSD
/dev/fuse        262144      37   262107    1% /etc/pve
tmpfs            812011     104   811907    1% /run/user/1000
ログイン後にコピー

Explanation:

Combining the -i option with the -B option specifies the block size and displays both the inode and block usage.

9. Include File System Type:

$ df -t ext4
ログイン後にコピー

Sample Output:

Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/nvme0n1p2 478096136 186495964 267240748  42% /
ログイン後にコピー

Explanation:

The -t option followed by a file system type shows disk space usage only for that specific file system type. In this example, it displays usage for the ext4 file system.

10. Show Disk Space in 1K Blocks:

$ df -k
ログイン後にコピー

Sample Output:

Filesystem     1K-blocks      Used Available Use% Mounted on
udev            16191444         0  16191444   0% /dev
tmpfs            3248044      1936   3246108   1% /run
/dev/nvme0n1p2 478096136 186496000 267240712  42% /
tmpfs           16240220     25348  16214872   1% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
/dev/nvme0n1p1    523248      3484    519764   1% /boot/efi
/dev/sda1      976698752 389951104 586747648  40% /media/ostechnix/SK_WD_SSD
/dev/fuse         131072        20    131052   1% /etc/pve
tmpfs            3248044      1644   3246400   1% /run/user/1000
ログイン後にコピー

Explanation:

Using the -k option shows disk space usage in 1K blocks.

These examples illustrate various scenarios where the df command can be used to obtain disk space usage information in Linux.

Now let us learn about du command.

2. du Command

The du command stands for "disk usage" and is used to estimate file and directory disk usage. It helps you determine the space consumed by individual directories or files, making it useful for identifying space-hogging directories or large files.

Example:

$ du -sh /path/to/directory
ログイン後にコピー

Explanation:

The command calculates the total disk usage (-s) of the specified directory and its subdirectories in a human-readable format (-h). It provides the sum of disk usage by displaying the total size (-h).

2.1. du Command Examples

Here are some examples of using the du command along with their explanations:

1. Basic Disk Usage for a Directory:

$ du dir1
ログイン後にコピー

Sample Output:

4400	dir1/dir2
50480	dir1
ログイン後にコピー

Explanation:

Running du followed by the path to a directory displays the disk usage of that directory (In this case, dir1) and its subdirectories.

2. Human-Readable Output:

$ du -h dir1
ログイン後にコピー

Sample Output:

4.3M	dir1/dir2
50M	dir1
ログイン後にコピー

Explanation:

Adding the -h option makes the output human-readable, displaying sizes in a more understandable format (e.g., KB, MB, GB).

3. Total Disk Usage of a Directory:

$ du -sh dir1
ログイン後にコピー

Sample Output:

50M	dir1
ログイン後にコピー

Explanation:

The -s option provides a summary of the total disk usage of the specified directory without displaying individual subdirectory sizes. The -h option makes the output human-readable.

4. Disk Usage of All Files and Directories in Current Directory:

$ du -h *
ログイン後にコピー

Sample Output:

4.3M	dir2
5.8M	document.pdf
116K	image.jpeg
4.0K	New Empty File
40M	video.webm
ログイン後にコピー

Explanation:

Running du with * displays the disk usage of all files and directories in the current directory.

5. Disk Usage Sorted by Size:

$ du -sh * | sort -hr
ログイン後にコピー

Sample Output:

40M	video.webm
5.8M	document.pdf
4.3M	dir2
116K	image.jpeg
4.0K	New Empty File
ログイン後にコピー

Explanation:

By piping the output of du to sort command, you can sort the disk usage in descending order (-r flag) to see the largest files or directories at the top. The -h option makes the output human-readable.

6. Disk Usage of Individual Files:

$ du -h dir1/document.pdf
ログイン後にコピー

Sample Output:

5.8M	dir1/document.pdf
ログイン後にコピー

Explanation:

You can use du to get the disk usage of individual files by providing the path to the file as an argument.

7. Disk Usage Excluding Directories:

$ du -d 1 -h --exclude=dir2 dir1
ログイン後にコピー

Sample Output:

45M	dir1
ログイン後にコピー

Explanation:

The --exclude option allows you to exclude specific directories from the disk usage calculation. In this example, the disk usage is calculated for the dir1 directory (i.e. parent directory), excluding the specified directory i.e. dir2. Here, the -d option specifies the depth or level of the directory hierarchy to be displayed. In this case, -d 1 limits the output to only the current directory and its immediate subdirectories.

8. Disk Usage of Multiple Directories:

$ du -h dir1/ Downloads/
ログイン後にコピー

Explanation:

You can provide multiple directory paths as arguments to the du command to get the disk usage of each directory separately.

9. Disk Usage of Current Directory and Subdirectories:

$ du -h .
ログイン後にコピー

Explanation:

Using . as the argument for du displays the disk usage of the current directory and all its subdirectories.

10. Disk Usage of the Largest Directories:

$ du -h --max-depth=1 dir1 | sort -hr
ログイン後にコピー

Sample Output:

50M	dir1
4.3M	dir1/dir2
ログイン後にコピー

Explanation:

By specifying the --max-depth option, you can limit the depth of the disk usage calculation. It is equivalent to -d option. In this example, it displays the disk usage of the top-level directories within the specified directory, sorted in descending order.

These examples demonstrate different ways to use the du command to analyze disk usage in Linux.

Now that we have explored the df and du commands, including their definitions and examples. I hope you have obtained a fundamental understanding of these two disk space analysis tools. With this knowledge in place, we can now shift our focus towards examining the difference between df and du with an example.

Difference between df and du Commands

  • Purpose: df shows the overall disk space usage for mounted file systems, providing an overview of available and used space on each partition. On the other hand, du focuses on estimating the disk usage of individual directories or files, helping you identify space-consuming elements.
  • Scope: df covers the entire file system, displaying disk space utilization for each mounted file system, while du allows you to drill down and analyze disk usage at the directory or file level.
  • Usage: df is commonly used to monitor disk space availability and identify potential storage constraints, while du is helpful for identifying directories or files that contribute significantly to disk space usage.

Example Scenario:

Suppose you have a file system with multiple partitions: /dev/sda1 mounted on / and /dev/sda2 mounted on /home. Running df -h will provide information about the disk space utilization for these mounted partitions. In contrast, running du -sh /home will estimate the disk usage of the /home directory and its subdirectories, helping you identify space-consuming directories within /home.

In summary, df provides an overview of disk space usage at the file system level, while du helps estimate disk usage at the directory or file level. By using both commands appropriately, you can gain insights into disk space utilization and effectively manage your storage resources in Linux.

Frequently Asked Questions

Here's the FAQ about df and du commands.

Q: What is the df command used for?

A: The df command in Linux is used to display information about file system disk space usage. It provides details such as total, used, and available space on mounted file systems.

Q: What is the du command used for?

A: The du command in Linux is used to estimate disk usage for directories and files. It helps identify the space consumed by individual directories or files.

Q: How do the df and du commands differ in their purpose?

A: The df command provides an overview of file system disk space usage, giving information about total, used, and available space. On the other hand, the du command estimates disk usage for directories and files, allowing for a more detailed analysis at the directory and file level.

Q: Can the df and du commands be used together?

A: Yes, the df and du commands serve different purposes and can be used in conjunction to gain comprehensive insights into disk space utilization. While df provides a high-level view, du allows for a granular examination of disk usage at the directory and file level.

Q: How can I use the df command to check disk space usage for a specific file system?

A: You can use the df command followed by the path to the specific file system to view its disk space usage. For example: df /dev/sda1.

Q: How can I use the du command to check disk usage for a specific directory?

A: To check the disk usage of a specific directory, use the du command followed by the path to the directory. For example: du /path/to/directory

Q: Can I exclude specific directories or files from disk usage calculations?

A: Yes, both the df and du commands provide options to exclude specific directories or files from the disk usage calculations. For example, with du, you can use the --exclude option followed by the directory or file name to exclude it from the calculation.

Q: Are there any additional options available for df and du commands?

A: Yes, both commands offer additional options that allow you to customize the output. For example, you can use the -h option with both commands to display sizes in a human-readable format.

Q: How can I get a summary of disk usage for a directory without including subdirectories?

A: With the du command, you can use the -s option to get a summary of disk usage for a directory without including subdirectories. For example: du -sh /path/to/directory.

Q: Are the df and du commands available on all Linux distributions?

A: Yes, the df and du commands are standard utilities in Linux and are available on most Linux distributions. However, specific options or output formats may vary slightly between distributions.

Conclusion

In this guide, we unraveled the mystery of df and du commands and provided example commands to analyze and understand disk space usage. When it comes to managing disk space in Linux, df and du commands play a vital role. For beginners, grasping the distinction between these commands and their practical usage is crucial.

Related Read:

  • How To Gather Comprehensive Disk Information On Linux

以上がディスクスペース分析は簡単になりました:LinuxでDFとDUコマンドを理解するの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Linuxは何に最適なものですか? Linuxは何に最適なものですか? Apr 03, 2025 am 12:11 AM

Linuxは、サーバー管理、組み込みシステム、デスクトップ環境として最適です。 1)サーバー管理では、LinuxはWebサイト、データベース、アプリケーションをホストするために使用され、安定性と信頼性を提供します。 2)組み込みシステムでは、Linuxは柔軟性と安定性のため、スマートホームおよび自動車電子システムで広く使用されています。 3)デスクトップ環境では、Linuxは豊富なアプリケーションと効率的なパフォーマンスを提供します。

Linuxの5つの基本コンポーネントは何ですか? Linuxの5つの基本コンポーネントは何ですか? Apr 06, 2025 am 12:05 AM

Linuxの5つの基本コンポーネントは次のとおりです。1。カーネル、ハードウェアリソースの管理。 2。機能とサービスを提供するシステムライブラリ。 3.シェル、ユーザーがシステムと対話するインターフェイス。 4.ファイルシステム、データの保存と整理。 5。アプリケーション、システムリソースを使用して機能を実装します。

基本的なLinux管理とは何ですか? 基本的なLinux管理とは何ですか? Apr 02, 2025 pm 02:09 PM

Linuxシステム管理により、構成、監視、メンテナンスを通じて、システムの安定性、効率、セキュリティが保証されます。 1。TOPやSystemCtlなどのマスターシェルコマンド。 2. APTまたはYUMを使用して、ソフトウェアパッケージを管理します。 3.効率を向上させるための自動スクリプトを書きます。 4.許可問題などの一般的なデバッグエラー。 5.監視ツールを介してパフォーマンスを最適化します。

Linuxの基本を学ぶ方法は? Linuxの基本を学ぶ方法は? Apr 10, 2025 am 09:32 AM

基本的なLinux学習の方法は次のとおりです。1。ファイルシステムとコマンドラインインターフェイス、2。LS、CD、MKDIR、3。ファイルの作成と編集などのファイル操作を学習するマスター基本コマンド、4。

Linuxの最も使用は何ですか? Linuxの最も使用は何ですか? Apr 09, 2025 am 12:02 AM

Linuxは、サーバー、組み込みシステム、デスクトップ環境で広く使用されています。 1)サーバーフィールドでは、Linuxは、その安定性とセキュリティにより、Webサイト、データベース、アプリケーションをホストするための理想的な選択肢となっています。 2)埋め込みシステムでは、Linuxは高いカスタマイズと効率で人気があります。 3)デスクトップ環境では、Linuxはさまざまなユーザーのニーズを満たすために、さまざまなデスクトップ環境を提供します。

Linuxデバイスとは何ですか? Linuxデバイスとは何ですか? Apr 05, 2025 am 12:04 AM

Linuxデバイスは、サーバー、パーソナルコンピューター、スマートフォン、組み込みシステムなどのLinuxオペレーティングシステムを実行するハードウェアデバイスです。彼らはLinuxの力を利用して、Webサイトのホスティングやビッグデータ分析などのさまざまなタスクを実行します。

Linuxの欠点は何ですか? Linuxの欠点は何ですか? Apr 08, 2025 am 12:01 AM

Linuxの欠点には、ユーザーエクスペリエンス、ソフトウェア互換性、ハードウェアサポート、学習曲線が含まれます。 1.ユーザーエクスペリエンスは、WindowsやMacOほどフレンドリーではなく、コマンドラインインターフェイスに依存しています。 2。ソフトウェアの互換性は他のシステムほど良くなく、多くの商用ソフトウェアのネイティブバージョンがありません。 3.ハードウェアサポートはWindowsほど包括的ではなく、ドライバーは手動でコンパイルされる場合があります。 4.学習曲線は急で、コマンドラインの操作をマスターするには時間と忍耐が必要です。

インターネットはLinuxで実行されますか? インターネットはLinuxで実行されますか? Apr 14, 2025 am 12:03 AM

インターネットは単一のオペレーティングシステムに依存していませんが、Linuxはその上で重要な役割を果たしています。 Linuxは、サーバーやネットワークデバイスで広く使用されており、安定性、セキュリティ、スケーラビリティに人気があります。

See all articles