Displaying Disk Space Used by Files
In addition to displaying the disk space used by directories, you can also use various commands in Linux to display the disk space used by individual files.
Using the ls
Command
The ls
command can be used to display the size of files. Here's an example:
ls -lh
This will display the file size in a human-readable format (e.g., KB, MB, GB) for each file in the current directory.
Using the du
Command
The du
command can also be used to display the disk space used by individual files. Here's an example:
du -h file.txt
This will display the disk space used by the file.txt
file in a human-readable format.
Using the find
Command
The find
command can be used to search for files based on various criteria, including file size. Here's an example:
find /var/log -type f -size +1M -exec du -h {} \;
This will display the disk space used by all files larger than 1MB in the /var/log
directory.
Using the ncdu
Command
The ncdu
(Ncurses Disk Usage) command provides a more interactive way to explore and visualize disk usage. It presents a directory tree-like interface that allows you to navigate through directories and view the disk space used by individual files and subdirectories.
To use ncdu
, simply run the following command:
ncdu /
This will start the ncdu
tool and display the disk usage for the root directory (/
).
By using these various commands, you can effectively display the disk space used by individual files in your Linux system, which is essential for identifying and managing large files that may be consuming valuable storage space.