What is the easiest way to free space on a hard drive?
"I played with cron once so it may have consumed my mass memory, but really I have no clue." No clue, you say? never would have guessed. :)
su - cd / du -s ./* | sort -n
du
shows disk usage, in blocks (1 block = 0.5 kilobytes, in all cases that matter to you.)-s
means, "summary", so it gives only a total for each argument "./*" being the argument.piping it into
sort -n
means sort numerically. The larger numbers at the bottom.So, you'll get a list of directories with the ones using the most space at the bottom.
If that's not enough help, say you get:
60380 ./root 142468 ./etc 537716 ./var 627264 ./lib 5757600 ./usr 28859472 ./home
and you see that ./home is the biggest piggy, ok,
cd
into /home, and do the samedu -s | sort -n
. Then you see who in /home is taking up space. (on a single user system, well, it's probably you.)Then cd into there, and do
du -s | sort -n
again.
Keep doing this until you find the culprit. When you find the culprit, you may say, oh yeah... that's my collection of hi-res renderings of Romulan Birds of Prey for my star trek RPG game that I'm building, so yeah, of course that takes up a lot of space, or you may say, of course that takes up a lot of space, so let's rm -fr that bad boy.
Magic words to remember:
du -s | sort -n
KDirStat is another option which will help you identify large files and directories.
I've used the Windows clone WinDirStat a lot and it is an awesome tool.
Linux tool ncdu
is very convenient in my opinion. It's like interactive du
.
Some features
- Text interface (
ncurses
); works via SSH, no Xserver needed. - Still you can move within directory tree to find large dirs/files quickly.
- You can delete dir/file from within the program.
Screenshot
Well, kind of. There's no point in pasting picture, text will be enough:
ncdu 1.10 ~ Use the arrow keys to navigate, press ? for help
--- / --------------------------------------------------------------------------
6,7GiB [##########] /usr
3,4GiB [##### ] /var
553,1MiB [ ] /lib
529,1MiB [ ] /opt
35,1MiB [ ] /etc
32,5MiB [ ] /home_old
16,4MiB [ ] /sbin
9,9MiB [ ] /bin
8,2MiB┌───ncdu help─────────────────1:Keys───2:Format───3:About──┐
3,8MiB│ │
1,3MiB│ up, k Move cursor up │
500,0KiB│ down, j Move cursor down │
124,0KiB│ right/enter Open selected directory │
12,0KiB│ left, <, h Open parent directory │
8,0KiB│ n Sort by name (ascending/descending) │
@ 4,0KiB│ s Sort by size (ascending/descending) │
@ 4,0KiB│ C Sort by items (ascending/descending) │
@ 4,0KiB│ d Delete selected file or directory │
0,0 B│ t Toggle dirs before files when sorting │
> 0,0 B│ g Show percentage and/or graph │
e 0,0 B│ -- more -- │
> 0,0 B│ Press q to continue │
> 0,0 B└──────────────────────────────────────────────────────────┘
> 0,0 B [ ] /home
> 0,0 B [ ] /dev
e 0,0 B [ ] /cpusets
e 0,0 B [ ] /cdrom
> 0,0 B [ ] /boot
Total disk usage: 11,3GiB Apparent size: 11,1GiB Items: 289029
Usage:
ncdu -x /foo/bar/mountpoint
Use sudo
(and caution!) when necessary. The -x
option is important, it makes ncdu
stay within single filesystem (du
has the same option). In the example (above) my /home
is on a different partition than /
where ncdu
started, therefore it does not count – thanks to -x
switch exactly.