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.)
vass: Small turtle with green leaf in its mouth (Default)

[personal profile] vass 2012-01-05 08:50 pm (UTC)(link)
ls is the command to view the files in a directory.
pwd tells you which directory you're currently in.
cd changes directory.

Suppose you were in a directory called /foo. You typed ls and found out that there were three directories in /foo - hat, ball, and cup. You want to go to cup. So you type cd cup.

To move up to the directory above the one you're in, you type cd .. So, if you were in /ball, cd .. would take you to /foo.

cd / will take you to the root of your filesystem, the directory all the other directories are in.
vass: Small turtle with green leaf in its mouth (Default)

[personal profile] vass 2012-01-05 08:52 pm (UTC)(link)
man [command] gives you the instruction manual for a command. So man ls will tell you how to use ls.

Be very careful with rm. Read the manual first.
vass: Small turtle with green leaf in its mouth (Default)

[personal profile] vass 2012-01-05 08:53 pm (UTC)(link)
Also: if it's in your filesystem (anything except for your home directory) then don't delete it.
pixel: (supernatural: sam reading)

[personal profile] pixel 2012-01-05 08:52 pm (UTC)(link)
You can pretty safely delete things (like music or pictures) in your home directory or directories inside your home directory, I wouldn't recommend deleting things not in your home directory, that is where you should land when you log into the cli. It'll be something like: /home/username

pwd : print working (current) directory
cd Documents : change directory to Documents
cd .. : go 'up' a directory
ls : list contents of current directory, to find files
rm file.txt : delete file

Once you've got some room to get the gui booted, one thing I've done that clears up some space is removing old kernels, google it for your distro and find a pile of instructions :)
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)