Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check which directory is occupying more space on a unix machine? [closed]

Tags:

unix

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
like image 577
python.beginner Avatar asked Apr 30 '14 16:04

python.beginner


People also ask

How do you check which is taking more space in Linux?

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.


2 Answers

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
like image 161
timrau Avatar answered Oct 24 '22 03:10

timrau


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.

like image 22
Floris Avatar answered Oct 24 '22 02:10

Floris