In Linux, every file is stored in a directory. The size of a directory is referred to as the directory size. To check the size of a particular directory, you can use several commands including du, df and ncdu. Each command has its own advantages and disadvantages that make it suitable for certain situations but not others.
What is a directory in Linux?
You might be wondering what a directory is and why you need to know how to check directory size. A directory is a container for files, which means that it lives in your home folder or on the root of your file system. It can contain other directories and files, but it can’t contain another directory at the same time (that would be weird).
A directory is basically just another way for Linux to organize things for you, making it easier for you to find the things you’re looking for. By default, every user has their own home folder to store their files in; this is also considered one big giant directory because all those individual subdirectories make up one huge container!
What is the difference between du and df in Linux?
du and df are two commands in Linux used to display the disk usage of a file or directory. Both commands can be used with or without arguments.
In this article, we’ll look at the difference between these two commands and their uses in Linux.
Using du command
You can use the du command to find out the size of a directory and all its subdirectories.
You can also use it to find out the size of a file:
Using df command
You can use the df command to find out the disk space usage of a directory. Use the -h option to view the output in human-readable format.
If you want to check how much space is available on your system, type: df -h
It gives output as shown below:
Using ncdu command
- The ncdu command is a disk usage analyzer.
- It allows you to view the contents of a directory tree, in a way similar to “ls”, but which also show the size of directories.
Using lsof command
The lsof command is used to list open files on a system.
The lsof command can be used to find directories and files that are in use by applications or processes.
Using findmnt command
The findmnt command is used to find out the file system information, like which file systems are mounted and where they are mounted.