Cheng
Cheng

Reputation: 9

How to find large directories?

I have a VPS on Linode,and its storage is almost full,so I want to find out the largest directories,when I type in

du -hs * | sort -rh | head -30

it shows below:

top 30 large directories and this is the storage use:

storage useage It seems the storage useage doesn't match the total storage,is there anyone can tell me why,thank you

Upvotes: 0

Views: 3236

Answers (2)

I use this command for the root folder / to check where the biggest directories are located, but you can use to any other directory of your choice

[sudo] du / -hxd 1 -t 1M | sort -hr
  • -h from human-readable, print sizes in human readable format (e.g., 1K 234M 2G)
  • -x skip directories on different file systems
  • -d from depth, print the total for a directory (or file, with --all) only if it is N or fewer levels below the command line argument
  • -t from threshold, exclude entries smaller than SIZE if positive, or entries greater than SIZE if negative

Upvotes: 1

Avihoo Mamka
Avihoo Mamka

Reputation: 4786

You can use this command for starters:

sudo du -h -x --max-depth=1 / | sort -hr

Where:

du - estimate file space usage

  • -h - print sizes in human readable format (e.g., 1K 234M 2G)
  • -x - skip directories on different file systems
  • --max-depth - print the total for a directory (or file, with --all) only if it is N or fewer levels below the command line argument; --max-depth=0 is the same as --summarize

sort - sort lines of text files

  • -h - compare human readable numbers (e.g., 2K 1G)
  • -r - reverse the result of comparisons

And you will get the list of 1st level directories sorted by size in descending order. Next is to investigate based on the largest directories, what is eating all the space, using the same command above but replace the directory parameter from / to the path you want to explore.

Upvotes: 2

Related Questions