I have multiple folders inside /local/mnt/workspace on my unix machine. How to know which folder is occupying more space? Is there a command?
/local/mnt/workspace
Linux command to check disk space using:df command – Shows the amount of disk space used and available on Linux file systems. du command – Display the amount of disk space used by the specified files and for each subdirectory.
Use the command du
.
du /local/mnt/workspace
To get size only for top-level directories:
du -k --max-depth=1 /local/mnt/workspace
To print the result in GB,
du -B1073741824 --max-depth=1 /local/mnt/workspace
Building on the various comments and permutations - the basic command you are looking for is du
(which stands for "disk usage"). You can use this with various options.
In its most basic form,
du directoryName
will give you a listing (in blocks) of all the directories below this one, and their size. For example, on my machine
du /etc
results in (first few lines only)
16 ./apache2/extra
16 ./apache2/original/extra
32 ./apache2/original
0 ./apache2/other
8 ./apache2/users
176 ./apache2
Note that it lists directories by depth, and then summarizes as it goes up a level (thus you see original/extra
and then original
which includes the size of extra
.)
Some helpful flags:
-k express result in kB rather than "blocks" (which can depend on your file system)
-s summarize result (don't give individual directories; just the final number)
-d go only to a certain depth (handy to see the result of directories "at your level"
without worrying about what goes on deeper down)
For your purpose, a good command might be
du -k -d1 /local/mnt/workspace | sort -rn | head -5
This will get you the top five directories (in terms of space used) at the level of workspace
. It will display your use in kB. Obviously you can change the parameter of head
to change the number of files you want to see.
With a tip of the hat to @fedorqui who suggested, in a comment, the use of sort
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With