Open In App

How to Check Disk Space in Linux

Improve
Improve
Like Article
Like
Save
Share
Report

Taking care of your computer’s storage is super important, especially in Linux. You need to keep an eye on how much space is left to make sure your Linux computer works well. In this guide, we’ll check out different ways to see how much space you have.

Linux is great because it has lots of tools to help you check your storage. This article will teach you how to use these tools, whether you’re new to Linux or you’re an experienced user. It’s all about making sure your computer stays healthy and runs smoothly.

How to Check Disk Space in Linux Using the `df` Command in Linux

The `df` command, short for “disk-free,” is a fundamental tool for displaying available and used disk space on your Linux system.

Syntax of `df` Command in Linux

df [OPTIONS]

The df command in Linux is used to display information about disk space usage on a file system. Here are some common options you can use with the df command:

Option

Description

-h

Human-readable output (e.g., KB, MB, GB).

–help

Display help information.

-T

Display the file system type.

-a

Display information about all file systems, including those with 0 blocks.

-i

Display inode information instead of block usage.

-k

Display block counts in 1K-byte blocks.

-m

Display block counts in megabytes.

-B <size>

Specify the block size to use.

–total

Display a total summary line.

–version

Display version information.

–sync

Invoke sync before getting usage info.

Practical Examples of `df` Command in Linux

`-h` Option in `df` Command in Linux

This option presents disk space information in a human-readable format. It displays sizes in gigabytes (GB), megabytes (MB), or kilobytes (KB) for easy comprehension. Here’s an example:

df -h

df -h

df -h

  1. Filesystem: Name of the file system or disk partition.
  2. Size: Total size of the file system or partition.
  3. Used: Amount of space already consumed.
  4. Avail: Available or free space on the file system.
  5. Use%: Percentage of used space relative to the total size.
  6. Mounted on: Directory where the file system is mounted in the system.

`-a` Option in `df` Command in Linux:

This option displays complete disk usage information, even if the “Available” field is 0. It’s useful when you want to see all filesystems, including those with no available space. Here’s an example:

df -a

df -a

df -a

`-T` Option in `df` Command in Linux:

Use this option to show the disk usage along with each block’s filesystem type, such as xfs, ext2, ext3, btrfs, etc. It helps you identify the filesystems associated with your storage devices. Here’s an example:

df -T

df -T

df -T

`-i` Option in `df` Command in Linux:

This option displays used and free inodes, which are data structures used by the filesystem to store file and directory metadata. It’s crucial for understanding inode usage on your system. Here’s an example:

df -i

df -i

df -i

How to Check Disk Usage in Linux Using the `du` Command in Linux

The `du` command is used to analyze the disk usage of files, folders, and directories on your Linux system.

Syntax of du command in Linux

du <options> <location of directory or file>

`-h` Option in `du` Command in Linux:

This option shows disk usage in a human-readable format for all directories and subdirectories. It allows you to see the space consumed by each directory in a more user-friendly manner. Here’s an example:

du -h /home/administrator/Documents/

Here you can replace “/home/administrator/Documents/” with your desider directory.

du -h

du -h

`-a` Option in `du` Command in Linux:

This option displays disk usage information for all files within the specified directory. It’s useful when you want to see the space occupied by individual files. Here’s an example:

du -a /home/administrator/Documents/

Here you can replace “/home/administrator/Documents/” with your desider directory.

du -a

du -a

`-s` Option in `du` Command in Linux:

Use this option to provide the total disk space used by a specific file or directory. It gives you a summary of the space consumed by the specified item. Here’s an example:

du -s  /home/administrator/Downloads/

Here you can replace “/home/administrator/Dowloads/” with your designer directory.

du -s

du -s

`ls -al` Command (List Contents) in Linux

The `ls -al` command lists the entire contents of a specific directory, including their sizes. It provides a detailed view of the files and directories within the target location, along with their permissions, owners, and timestamps.

ls -al

ls -al

ls -al

`stat` Command (File/Directory Information) in Linux

The `stat` command, followed by the name of a file, directory, or filesystem, displays detailed information about its size and other statistics. It offers a comprehensive overview of the selected item’s attributes, such as size, access permissions, and timestamps.

stat Downloads/

Here you can replace “Dowloads/”

stat

stat

`fdisk -l` Command (Disk Partition Information) in Linux

The `fdisk -l` command reveals disk size and partitioning information, helping you understand your storage configuration. It lists the partitions on your storage devices, including their sizes and types.

fdisk -l

fdisk -l

fdisk -l

Ways to Check Disk Space in Linux – FAQs

How to Sort Files By Size in Linux?

To sort files by size in Linux, you can use the du (disk usage) command along with other utilities like sort. Here’s an example:

du -h | sort -rh

  • du -h: Displays disk usage in human-readable format.
  • sort -rh: Sorts the output in reverse order (-r) and numerically (-n) based on human-readable file sizes.

This command will show a list of files and directories sorted by their sizes, with the largest ones at the top.

How to Check Disk Space in Linux?

To check disk space in Linux, you can use the df command. Here are some examples:

  • To see an overview of disk space usage for all mounted file systems in human-readable format:
df -h

  • To check the disk space usage for a specific directory (e.g., the root directory `/`):
df -h /

How can I identify the largest file on my Linux system?

To find the largest directories and files on your Linux system, you can use the `find` and `du` commands together.

Here’s an example:

du -h / | sort -rh | head -n 10



This command will display the top 10 largest directories and files on your system, sorted by size. Adjust the number after `head -n` to show a different number of results.

What is the key difference between the ‘df’ and ‘du’ commands in Linux?

The df command shows information about disk space usage on the file system level, while the du command provides disk usage information for directories and files. Example:

df -h

And

du -h /path/to/directory

How do I check the disk space usage for a specific user in Linux?

du -h /home/username

Replace “username” with the actual username for which you want to check disk space usage. This command will display the disk space usage for the specified user’s home directory.

designer

Conclusion

In conclusion, managing storage is crucial for Linux computers’ optimal performance. This article covers essential commands, including ‘df’ for monitoring disk space, ‘du’ for analyzing file and directory usage, ‘ls -al’ for detailed directory content, ‘stat’ for file statistics, and ‘fdisk -l’ for partition information. These tools cater to both beginners and experienced users, ensuring your Linux system runs smoothly by effectively managing and monitoring storage resources.



Last Updated : 30 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads