To print the size of the root directory / in Ubuntu, you can use the df command which reports the amount of disk space used and available on filesystems. To see the size of the root directory /, run the following command in the terminal:
df -h /
Here's a breakdown of the command options:
df stands for "disk filesystem".
-h option stands for "human-readable". It will print sizes in human-readable format (e.g., KiB, MiB, GiB).
The output will look something like this:
User
print subfolders size too
Assistant
To print the sizes of subfolders within a directory in Ubuntu, you can use the du command with the --max-depth option to control the depth of the directory hierarchy you want to inspect. For instance, to print the size of the root directory / and its immediate subfolders (1 level deep), you can run:
sudo du -h --max-depth=1 /
Here's what the options mean:
du stands for "disk usage".
-h stands for "human-readable", making the output easier to read by converting it to Byte, Kilobyte, Megabyte, etc.
--max-depth=1 specifies the level of subdirectories you want to display. Adjust the number for deeper directory levels.
/ specifies the directory for which you want to see the size, which is the root directory in this case.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 30G 12G 17G 42% /
In this output, you can see the following information regarding the / (root) filesystem:
Size: Total size of the root filesystem.
Used: Amount of disk space used.
Avail: Amount of disk space available.
Use%: Used percentage of the disk.
Mounted on: The directory on which the filesystem is mounted, which will be / for the root filesystem.
Please note that this command shows the size of the filesystem that the root directory / is part of, rather than the total size of all files and directories within the /. To calculate the actual size of all files and directories within /, you would use the du (disk usage) command, although this is generally not done on / because it contains system files, and it would take a long time to calculate. However, if you really needed to, the following command could be used (not recommended):
sudo du -sh /
But be cautious using this command as it will try to calculate the size of every file under root, including special filesystems and mounted devices that may cause problems. This command typically requires root privileges to access all directories and files, so sudo is used.
Because some directories within / require root permissions to read, you should run the command with sudo.
The output will list the sizes of the root directory and its immediate subfolders:
8.0K /snap
16K /lost+found
1.2M /tmp
...
Remember that running this on the root directory can potentially produce a lot of output since every immediate subdirectory of / will be listed. If you only want to inspect a specific subdirectory and its children, replace / with the path to that subdirectory. For example, to inspect the /var directory, you would run:
sudo du -h --max-depth=1 /var
Be aware that running the du command on large directories or directories with lots of files can take time and potentially slow your system down while the disk usage is being calculated.