Users who have switched recently to Linux or still learning it might be curious to know how to see the disk space usage for a file or folder using the terminal application in Linux. While it is easy to view the size with any graphical file manager app, it isn't so obvious via the command line for someone who hasn't used Linux before. Here is how you see the size.
Linux comes with a number of commands which can show you detailed information about files and folders. The first command you can use to see the size of files is ls. "ls" serves the same purpose as the good old DOS command "dir", which lists a directory's contents. To make "ls" show you file sizes in bytes, type it as follows:
ls -l
The marked value in the output is the file size in bytes:
You can make it show the size in a more user friendly format. Add the -h switch and execute ls as follows:
ls -lh
This will produce the following result:
The size will be in kilobytes, megabytes and gigabytes, which gives you a better idea of how much space a file occupies.
The ls command does not show you the size of a directory. For that, you should use the command du. The syntax is as follows:
du -s /etc
Note that you can use du to view the size of files too. This can be useful to see the size of a single file, as follows:
du -h /path/filename
du --apparent-size -h /path/filename
The result will be as follows:
That's it.
Support us
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options: