Friday, 8 October 2010

System Info from the Command Line

Bizarrely it can be a frustrating experience to get sensible information about your system from a linux machine. Fortunately, this has been sorted out in the latest versions of Ubuntu which come with the [name of app] which seems to give one a full overview of the hardware installed in the system. Ubuntu's DIsk Usage Analyser is a very useful way of finding out what is taking up space in the system.

Those graphical applications are dependency heavy though, and require you to have the whole of Gnome installed before they are prepared to work. I therefore present herein a non-exhaustive list of commands which get you to the same kind of useful information:

df -h

This gives you the total [d]isk space used and [f]ree in [h]uman readable numbers.

df -hH

This gives you the same information in marketing megabytes, not actual megabytes.

du [dir] -h

Gives you the [d]isk [u]sage of a directory and all its subdirectories individually.

du [dir] -hs

Gives you the [d]isk [u]sage of the whole directory in one number.

top -i
...brings up a fullscreen updating display of the current active processes, and general memory/swap usage.

ps -auxf | sort -nr -k 4 | head -10
...should show you the top ten processes by memory usage.

free -m
...shows you memory usage only in [m]egabytes.

sudo du --max-depth=1 --exclude=*dev* --exclude=*tmp* --exclude=*proc* | sort -n -r

This is a useful command to run from the root directory as it lists the space used by all subfolders to that directory only. It does not go below the subfolder level ([max-depth=1]). It does not work with [-h] as the sort ([| sort -n -r]) gets confused and does not deal with the M or K distinction. In other words a 20000k file is treated as larger than a 20m file. The excludes are useful because proc and dev are virtual and do not take up any space on the disk. I had tmp mounted to a ramdisk when I was doing my Amiga project, so I also wanted to exclude that.

This following does seem to do the sort better (or at all):

du -ks --exclude=*dev* --exclude=*tmp* --exclude=*proc* * | sort -nr | cut -f2 | xargs -d '\n' du -sh

I have no idea what the [cut] or [args] bits do, but they seem to sort out (ha ha) the sorting problem.

To get Battery information from the command line, you use the following two commands:

cat /proc/acpi/battery/BAT1/state
cat /proc/acpi/battery/BAT1/info

The variable here is the [BAT1] bit. Yours may be BAT0 or something else. Just check the contents of the directory and you should find something. There is a useful perl script here which extracts and displays the information produced by the preceding commands.

No comments:

Post a Comment