CLASS="CHAPTER" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" >

Chapter 8. Finding information about the system

Table of Contents
Date/Time/Calendars
Finding information about partitions

time

If you are looking for how to change the time please refer to date here: the Section called Date/Time/Calendars.

time is a utility to measure the amount of time it takes a program to execute. It also measures CPU usage and displays statistics.

Use time -v (verbose mode) to display even more detailed statistics about the particular program.

Example usage:

time program_name options
/proc

The files under the /proc (process information pseudo file-system) show various information about the system. Consider it a window to the information that the kernel uses.

For example:

cat /proc/cpuinfo

Displays information about the CPU.

less /proc/modules 

Use the above command to view information about what kernel-modules are loaded on your system.

dmesg

dmesg can be used to print (or control) the “ kernel ring buffer”. dmesg is generally used to print the contents of your bootup messages displayed by the kernel. This is often useful when debugging problems.

Simply type:

dmesg
df

Displays information about the space on mounted file-systems. Use the -h option to have df list the space in a 'human readable' format. ie. if there are 1024 kilobytes left (approximately) then df will say there is 1MB left.

Command syntax:

df -options /dev/hdx

The latter part is optional, you can simply use df with or without options to list space on all file-systems.

who

Displays information on which users are logged into the system including the time they logged in.

Command syntax:

who
w

Displays information on who is logged into the system and what they are doing (ie. the processes they are running). It's similar to who but displays slightly different information.

Command syntax:

w
users

Very similar to who except it only prints out the user names who are currently logged in. (Doesn't need or take any options).

Command syntax:

users 
last

Displays records of when various users have logged in or out. This includes information on when the computer was rebooted.

To execute this simply type:

last
lastlog

Displays a list of users and what day/time they logged into the system.

Simply type:

lastlog
whoami

Tells the user who they are currently logged in as, this is normally the usename they logged in with but can be changed with commands like su). whoami does not need or take any options.

Simply type:

whoami
free

Displays memory statistics (total, free, used, cached, swap). Use the -t option to display totals of everything and use the -m to display memory in megabytes.

Example:

free -tm

This will display the memory usage including totals in megabytes.

uptime

Print how long the computer has been “up”, how long the computer has been running. It also displays the number of users and the processor load (how hard the CPU has been working...).

The w command: The w command displays the output of the uptime command when you run this command. You could use the w command instead of uptime.

uname

uname is used to print information on the system such as OS type, kernel version et cetera.

Some uname options:

  • -a --- print all the available information.

  • -m --- print only information related to the machine itself.

  • -n --- print only the machine hostname.

  • -r --- print the release number of the current kernel.

  • -s --- print the operating system name

  • -p --- print the processor type.

Command syntax:

uname -options
xargs

Note that xargs is an advanced, confusing, yet powerful command. xargs is a command used to run other commands as many times as necessary, this way it prevents any kind of overload... When you run a command then add a “| xargs command2”. The results of command1 will be passed to command2, possibly on a line-by-line basis or something similar.

Understanding xargs tends to be very difficult and my explanation is not the best. Refer to the examples below or try [6] of the Bibliography for another xargs tutorial.

Alternatives to using xargs: Please note that the below explanation of xargs is not the strongest (at the time of writing I could not find anything better :()).

Alternatives may include writing a simple bash script to do the job which is not the most difficult task in the world.

Examples:

ls | xargs grep work

The first command is obvious, it will list the files in the current directory. For each line of output of ls, xargs will run grep on that particular line and look for the string “work”. The output have the each time grep is executed on a new line, the output would look like:

file_name: results_of_grep 

If grep didn't find the word then there would be no output if it had an error then it will output the error. Obviously this isn't very useful (you could just do:

grep 'word' *

This is just a simple example...

xargs also takes various options:

  • -nx --- will group the first x commands together

  • -lx --- xargs will execute the command for every x number of lines of input

  • -p --- prompt whether or not to execute this particular string

  • -t --- (tell) be verbose, echo each command before performing it

  • -i --- will use substitution similar to find's -exec option, it will execute certain commands on something.

Example:

ls dir1 | xargs -i mv dir1/'{}' dir2/'{}'

The {} would be substituted for the current input (in this example the current file/directory) listed within the directory. The above command would move every file listed in dir1 to dir2. Obviously this command won't be too useful, it would be easier to go to dir1 and type mv * ../dir2

Here is a more useful example:

\ls *.wav | xargs -i lame -h '{}' '{}'.mp3

This would find all wave files within the current directory and convert them to mp3 files (encoded with lame) and append a “.mp3” to the end of the filename, unfortunately it doesn't remove the .wav and so its not too useful...but it works.

Date/Time/Calendars

There is one command to change both the date and time on a UNIX like system, date, there is also a simple calendar utility, cal. If you are looking to change the timestamps on files please see Chapter 8

date

Tells you the date (and the time) and is also used to set the date/time.

To set the date, type date MM:DD:YYYY (American style date) where MM is month, DD is the number of days within the month and YYYY is the year.

For example to set the date to the 1st January 2000 you would type:

date 01:01:2000

To set the time (where the -s option is to set a new time), type:

date -s hh:mm:ss

Another useful option you can use is --date=“string” (or -d “string”) option to display a date from x days ago or in x days (or x weeks, months, years et cetera). See the examples below.

Examples:

date --date="3 months 1 day ago"

Will print the date 3 months and 1 day ago from the current date. Note that --date=”x month x day ago” and -d “x month x day ago” are equivalent.

date -d "3 days"

The above command will print the date 3 days in the future from now.

cal

Typing cal will give you the calendar of the present month on your screen, in the nice standard calendar format. There are various options to customise the calendar, refer to the info/man page.

Example:

cal -y year

Will display a calendar for a specific year, simply use cal -y to print the calendar for the current year.

cal 2 2004

This will display the calendar for February 2004