Chapter 8. Finding information about the system

Table of Contents
8.1. Date/Time/Calendars
8.2. Finding information about partitions

time

If you are looking for how to change the time please refer to date here: Section 8.1.

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...).

TipThe 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.

NoteAlternatives 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 a12264.htm a12264.html b12722.htm backing-up-files.html book1.htm c10407.htm c10694.htm c107.htm c10866.htm c1089.htm c11270.htm c11412.htm c1195.htm c2086.htm c2269.htm c2690.htm c4268.htm c4975.htm c6239.htm c6435.htm c8113.htm c8319.htm c9295.htm c962.htm c9978.htm checking-the-hard-disk.html command-substitution.html compression.html concept-definitions.html contributors.html controlling-processes.html controlling-services.html controlling-the-system.html conventions.html date-time-calendars.html directing-input-ouput.html disclaimer.html doc-index.html duplicating-disks.html feedback.html file-permissions.html finding-information.html finding-packages-tools.html finding-text-within-files.html further-reading.html general-shell-tips.html gnu-free-documentation-licence.html GNU-Linux-Tools-Summary.html graphics-tools.html hard-disk-partition-info.html help.html i12910.htm icon_smile.png index.html internet-specific-commands.html introduction.html legal.html license.html managing-users.html mass-rename.html mathematical-tools.html mini-guides.html miscellaneous.html mounting-and-unmounting.html network-commands.html network-configuration.html other-key-combinations.html performing-more-than-one-command.html references.html remote-administration.html resources-used-to-create-this-document.html rpm.html rsync.html scheduling.html security.html shell-tips.html shutting-down.html some-basic-security-tools.html sources-of-document.html tar.html text-editors.html text-filter-tools.html text-information-tools.html text-manipulation-tools.html text-related-tools.html text-viewing-tools.html the-command-line-history.html the-unix-tools-philosophy.html usage-input-output.html users-and-groups.html using-filesystem.html virtual-terminals.html who-would-not-want-to-read-this-guide.html who-would-want-to-read-this-guide.html wildcards.html working-files-folders.html working-with-ms-dos.html working-with-the-file-system.html x10099.htm x10181.htm x1039.htm x11569.htm x11606.htm x11655.htm x12429.htm x12637.htm x1712.htm x1877.htm x2005.htm x2361.htm x2563.htm x2622.htm x299.htm x3289.htm x335.htm x392.htm x4055.htm x4892.htm x5152.htm x5368.htm x6066.htm x611.htm x6546.htm x662.htm x6823.htm x696.htm x6993.htm x7619.htm x7969.htm x8751.htm x9094.htm x9543.htm ../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.