The Linux operating system can seem a bit technical but generally offers greater control to users. Managing disk space on Linux servers is an incredibly important task; if you run out of space on a server, your websites can crash.
In the following tutorial, we’re going to learn how to check disk space in Linux. Obviously, you’ll need a Linux-based operating system, a user account that has root (or sudo) privileges, and a basic understanding of the command-line interface.
Checking Disk Space using the df Command
To check the disk space on Linux, simply open the terminal window by pressing Ctrl+Alt+T. Then, just write “df” and press Enter.
This stands for disk free and shows you the total amount of space taken by different drives. All values are shown in 1 KB blocks. To display the disk space in megabytes (MB) or gigabytes (GB), use the following command:
df - h
This shows usage in KBs, MBs, and GBs. The command essentially outputs data that’s presented in several columns, including:
- File system: This shows the name of each drive on the server, including partitions and physical (or virtual) drives.
- Size: Total size of the files on each drive.
- Used: Total file size consumed.
- Avail: Total file size still available.
- Use%: Shows you the percentage of disk usage.
- Mounted on: This shows the directory in which the file system is present. For instance, /dev is the location of device files, while /sda refers to the first SCSI disk. Others, like /tmpfs, simply refer to temporary file storage.
Checking Disk Space using the “du” Command
Another option is to use the “du” command. This command gives you the disk usage and can be used to show disk usage for individual directories.
Just open the terminal and write
du - h
This will show you all the contents of the directory you’re in, as well as how much space each directory is using.
If you get a message stating that permission’s been denied, you can use your sudo privileges to overwrite it. Simple use the following command:
sudo su - hs /etc
If you want to run the “df” command to check the usage on the primary hard drive, simply use the following:
Or, you can use this to check the space on a specific mount point, such as
That’ll show you the hard drive usage on the boot drive.
We hope you’ve found this quick Linux guide useful & understand how to use the df and du commands to check your disk space. Remember you can always add the help flag to both of these commands (i.e. df –help or du –help) to display a complete list of options.
Any questions about Linux you’d like to see us cover in a future guide? Feel free to join the conversation by dropping a comment below or Tweeting at us! 💬