Home » Questions » Computers [ Ask a new question ]

What is the easiest way to free space on a hard drive?

What is the easiest way to free space on a hard drive?

My hard drive became full. I am looking for ways to locate the things that use most of my disk space. I played with cron once so it may have consumed a great deal of space, but really I have no clue.

Asked by: Guest | Views: 139
Total answers/comments: 4
Guest [Entry]

"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."
Guest [Entry]

"""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 same du -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"
Guest [Entry]

"Per the ""Linux Server Hacks"" by O'Reilly

alias ducks='du -cks * | sort -rn | head -11'

Then go to any directory and run the alias"
Guest [Entry]

"Software built-in: Disk Usage Analyzer.
Fig. 1 Polar coordinate view of masi's /,
Fig. 2 Rectangular view of masi's / where you move your mouse to visualize contents



Delete things which you do not need then

manually after inspection carefully
clean packages in apt-get

# http://superuser.com/a/113904/2005
su
apt-get autoclean

Example output in my Asus Zenbook UX303UA where I use the Linux kernel backports (currently 4.6)

root@masi:/home/masi# apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done
Del chromium 53.0.2785.89-1~deb8u1 [42.0 MB]
Del chromium 52.0.2743.116-1~deb8u1 [41.3 MB]
Del libtomcat7-java 7.0.56-3+deb8u3 [3,623 kB]
Del mysql-common 5.5.50-0+deb8u1 [81.8 kB]
Del libmysqlclient18 5.5.50-0+deb8u1 [675 kB]
Del libservlet3.0-java 7.0.56-3+deb8u3 [314 kB]
Del linux-libc-dev 3.16.7-ckt25-2+deb8u3 [1,025 kB]

Remove unused packages if you do not have dependency problems

apt-get autoremove

...

There are also tools which try to find duplicate files in your system

use merge and diff tools too to find duplicates in directories
fdupes, however, can delete wrong files so I am not using it anymore
...

If you have an updated working tree and you want to replace an old one in your other system

Use rsync by knowing your case precisely because it is sharp - can be efficient or work against you if you do not know what you are doing

To rsync -rtvuc in Two Filesystems?
...

OS: Debian 8.5
Window manager: Gnome 3.14"