+4 votes
272 views
Command to view system disk usage and Linux disk space

in Linux / Unix by (552k points)
reopened | 272 views

1 Answer

+5 votes
Best answer

1. View disk space information using the df command in Linux
2. View disk space information using the du command in Linux
3. View disk space information for image capture using the btrfs command on Linux

The hard disk is one of the essential and fundamental components in all equipment since it installs the operating system, applications and serves to store all our information, as well as backing it up by means of backup copies..

Nowadays there are hard drives of great capacity , but little by little this space is occupied with new information and the storage limit reaches the top which can generate inconsistencies such as reboots, shutdowns, file opening lock, slowness and more because which, regardless of the type of user we are, is recommended to constantly monitor this capacity and today we will learn to verify the real-time use of the hard disk in Linux environments.

To keep up, remember to subscribe to our YouTube channel! SUBSCRIBE


1. View disk space information using the df command in Linux


The df command has been developed in order to provide information about the total, occupied and free space on the disk of our operating system in a simple way.

With the df command, information about the file system in which each file is hosted or by default on all current file systems will be displayed..

Step 1

The basic syntax to use this command is as follows:
 df [options] [device] 
Step 2

We can directly use the df command and the result will be the following: image
Step 3

There we will see each file system with details such as:
  • Used space
  • Free space
  • Location where it is mounted, etc.
Step 4

We can use the -h parameter to see this information in a readable format:
 df -h 
image
Step 5

With the df command it will be possible to obtain precise information about a device or mount point, for example, if we want to see the details of the point / dev / sda we will execute the following:
 df / dev / sda 
Step 6

Or, we can see details of a specific route, for example:
 df / home 
image
Step 7

There the following columns stand out:
Filesystem
Indicates the origin of the mounting point, which is generally a device.
1K blocks
It is the total number of blocks.
Used
Indicates the number of blocks used.
Available
It is the number of available blocks.
Use percentage
Indicates the percentage of Used divided by Size.
Mounted on
It is the target or mount point.
Step 8

The df command gives us the possibility to specify only which columns have to be displayed, for this we will use the following syntax:
 df --output = field1, field2, .. 
Step 9

For example, we can execute the following:
 df --output = source, used, avail / home / 
Step 10

The result will be only those three columns of the selected point: image
Step 11

To visualize all the available fields we can execute the following line:
 df –o 
image
Step 12

We also have the following alternatives for use:
df -h
Display the data in human format.
df -m
Display the output in Megabytes.
df -k
Display the output in Kilobytes, default value.
Step 13

Linux has a system called inode, an inode is a basically a data structure in the file system that is responsible for storing all the information about the file, the df command also allows us to see the space of said inodes by executing any of the following options:
 df -i df -i -h 
image
Step 14

If we want to verify the file system type of each mount point, such as ext4, btrfs, ext2, nfs4, fuse, cgroup and more, it will be necessary to use the following command:
 df -T df -T -h df -T -h / home / (Specific path) 
image
Step 15

In the same segment, if we want to exclude any file system we must add the -x parameter like this:
 df -x ext3 
Step 16

If we want all output file systems that have a size of zero blocks to be deployed, we can execute:
 df -a 
image
Step 17

To obtain more information about this command we can execute:
 df –help 

2. View disk space information using the du command in Linux


The du command is another of the alternatives that Linux offers us to obtain information about disk space based on a set of files, directories or recursively.
Step 1

To use this command we have the following basic alternatives:
 du du / route du [options] [directories and / or files] 
image
Step 2

These options allow us to see the names and space consumption of each of the directories, including all subdirectories in the directory tree. If we want to see these results in human, readable format, we execute the following:
 du -h 
image
Step 3

We can see details of a specific directory using one of the following options:
 du / home / du -h / home / 
image
Step 4

To see a summary of the information where only the total disk space occupied by a directory tree is displayed and the subdirectories are deleted, we can execute the following:
 du -s / home du -sh / home 
image
Step 5

If the objective is to visualize all the file systems we execute:
 du -a / home du -a -h / home 
image
Step 6

With the du command we can see in detail the space of a specific type of extension, for example, if we want to see the space of all the text files we execute the following:
 du -ch * .txt 
image
Step 7

We can list a certain number of directories to see their space, for this we execute the following syntax:
 du -a / route / | sort -n -r | head -n # to list 
image

3. View disk space information for image capture using the btrfs command on Linux


For the btrfs file system, which is a special file system for capturing images, we must use the btrfs fi df command to view the space usage information for a mount point.
Step 1

The syntax to use is:
 btrfs filesystem df / path / btrfs fi df / dev / path btrfs fi df [options] / path / 
image
Step 2

To see the raw numbers in bytes, we will execute the following:
 btrfs fi df -b / home 
image
Step 3

Alternatively we can execute:
Show data in Kilobytes
 btrfs fi df -k / home 
Show data in Megabytes
 btrfs fi df -m / home 
Show data in Gigabytes
 btrfs fi df -g / home 
Show data in Terabytes
 btrfs fi df -t / home 

With these simple commands it will be possible to know in detail the space available on Linux and thus better manage this important section on every computer.


by (3.5m points)
edited

Related questions

+3 votes
1 answer
asked Nov 14, 2019 in Linux / Unix by backtothefuture (552k points) | 415 views
+3 votes
1 answer
asked Oct 22, 2019 in Linux / Unix by backtothefuture (552k points) | 252 views
+3 votes
1 answer
+3 votes
1 answer
asked Oct 6, 2019 in Linux / Unix by backtothefuture (552k points) | 223 views
+4 votes
1 answer
asked Sep 29, 2019 in Linux / Unix by backtothefuture (552k points) | 335 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users