sylvaine: Dark-haired person with black eyes & white pupils. (Default)
Sylv ([personal profile] sylvaine) wrote in [community profile] linux4all2012-01-05 09:07 pm

clearing disk space in CLI?

Whilst trying to get my GUI back, I got the error message "Keyboard initialisation failed. This could be a missing or incorrect setup of xkeyboard-config.", which google tells me means I need to free up disk space.

As far as I know, I need to use the rm command to do this, but how do I figure out which files to delete without my GUI? I'm deathly afraid that I'll delete something I need.

(Please bear in mind that I'm an utter noob when it comes to Linux.)
kerravonsen: 9th Doctor wearing his headlamp: Technical wizard (technical-wiz)

[personal profile] kerravonsen 2012-01-05 09:05 pm (UTC)(link)
Okay, you need to do some detective work.
If you've run out of disk space, you need to track down what unusual things are taking up all the space.

First command to use: df
This stands for "disk free" - it shows how much free space there is on each disk (partition) of your system. "df -h" gives the numbers in a more "human-friendly" format.

Second command to use: du
This stands for "directory usage"; it tells you how much space each directory is using. The "-s" option gives a summary; the "-h" option gives it in "human-friendly" format.

If you want to learn more about those commands, the "man" command is your friend. The name "man" is short for "manual" and if you go "man name-of-command" it will give you the manual page for that command. You can even go "man man"!

So... back to tracking down disk usage.

As I said, use "df" first. This should tell you which - if any - partition is full or near-full. The last column of the output is "Mounted on" - that tells you what directory that partition is mounted on, and that's the directory you should investigate.

Use the "cd" command to go to that directory.

Use "du -h -s *" to get a summary of the disk usage of all the sub-directories in that directory. Note that this can take a long time, and you may need to use "sudo du -h -s *" instead, if you get a lot of errors saying that you don't have permission to read a directory.

Look at the output and see which directory is taking up the most room.
Then cd to that directory, and do the "du" stuff again. Keep on doing this until you narrow down the culprit a bit closer. Then look at the files in that directory with "ls". Then you have to figure out whether those files belong there or not, which is very tricky for a newbie, I'm afraid. You certainly don't want to be deleting vital files!

A few rules of thumb:
* Files in /tmp are usually okay to delete, but check the date on them; older files are usually safer than newer ones to delete, because it's less likely that they're currently being used.
* Files in /var/log are usually okay to delete, because they're the output of logging what the programs are doing. Again, the older files are safer to delete than the newer ones. This is also a good place to look for files taking up a lot of space, because it could be that some process is outputting a LOT of log messages.
* Never delete files in /usr/bin or /usr/lib - these are program files and if you want to remove them, you should use the package manager to remove the program that they're associated with.
* A better rule of thumb is "if you don't know what it is or what it's for, don't delete it".
Edited (more thoughts) 2012-01-05 21:10 (UTC)