Skip to main content Skip to navigation

4. Linux utilities

1. who and w

To find out which users are logged into the machine as well as yourself, type who. This command comes with many options. Read the man pages to find out more. The output of who comprises several columns. The first column gives the userid's of all users logged in, the second column lists the terminal where each user is logged in, the next few columns give the date and time when each user logged in, and the final column gives the network address of each user. Below is typical output for the who command:

cudcu      pts/5        Aug  2 10:22    (mimosa)
eosbab     pts/43       Jan 27 07:48    (curiousyellow)
phrjf      pts/9        Aug 12 15:18    (
eosbab     pts/10       Aug 30 07:54    (lorretta)
marxaj     pts/11       Aug 24 09:04    (
phsday     pts/90       Jul 14 08:10    (
stsbm      pts/58       Aug 30 09:57    (kiki)
cudau      pts/113      Jul 14 10:17    (flaky)

You can go further than this and use another command, w, to find out what current process each user is running on a given machine. Again, just type w at the terminal and hit return. The output is similar, except now there are some columns giving CPU time used, as well as the name and arguments of each current process (under the heading what. Below is typical output for the w command:

User     tty           login@  idle   JCPU   PCPU  what
aosaaf   pts/31       10Mar05 2days  13:38  13:38  ssh primrose
ccscab   pts/36       11:39pm 11:42      2      2  pine -i
cudcu    pts/27        2Aug0528days   2:03   2:03  mutt -f /home/unit/cu/dcu/Mail/r
phsday   pts/46       14Jul05  1:47   2:27      1  -tcsh
mssbal   pts/50        8:47am           24     12  w
helpdesk pts/51        8:48am           12      1  pine -i
cudcu    pts/34       19Jul0525days   5:53         -tcsh
cusbae   pts/56       20Aug05 10:51   1:09     25  pine -f MAILBOX -i
helpdesk pts/64        8:19am    19      8         pine -i
pssbx    pts/67       11:14am    12                pine
cudbu    pts/52        8:55am     9     34     30  /package/StarOffice/sparc/Office

Back to top

2. Getting the time and date

To get the current time and date as set for your machine, just type date and hit return.

Back to top

3. Displaying a calendar

You can display the calendar for the current month this year (or at least according to the date your machine is set for), by typing cal and hitting return.

cal comes with a few options. Typing cal -y outputs the calendar for the entire current year. Typing cal year, you can display the calendar for any given year.

Back to top

4. Setting job priorities

When you launch a job from the command line, you can set the priority by using the command nice . the basic syntax of this command is:

nice priority number command

where priority number can range between 1 and 19 (see Section 1.10.3 to remind yourself about job priority).

Back to top

5. Querying disk usage

You can find out how much free disk space for each mount point on your machine by using the df command. As usual,this command comes with lots of options.

Putting it into Practice:

Find out about some of the options associated with the df command.
What option do you need to find out disk usage in units of 'human readable' format?

A related command is du. You can use this command to determine how much space a file (including directories) occupies. It comes with similar options to df.

Back to top

6. echo

You have already the echo command (see Section 1.12.4 ). The echo command will send (echo) the input string to standard output. This string can be text specified by the user, or can be from substitution of a shell variable (such as an environment variable). The general syntax of this command is as follows:

echo options string


echo can be used without options, e.g to just print out the string every cloud has a silver lining , you could type at the shell prompt
 echo 'every cloud has a silver lining'
after hitting return, this string should be printed at your x-term.
Notice that this string contains whitespace, this is why the string is enclosed in quotation marks

As you have already seen, echo can be used to print out shell variables (such as environment variables) to standard output. However, if you want to print out both plain text AND environment variables, you need to use double quotes (") instead of single quotes (').

Putting it into Practice:

Try using echo to print out a combination of user-supplied text and environment variables. Type the following at the prompt:
 echo "hey $USER, every cloud has a silver lining" 
The output should have subsituted your actual user name for $USER
Now try typing out the same command, but with single quotes, i.e
 echo 'hey $USER, every cloud has a silver lining'
How is this new output different?

Back to top

7. Changing passwords

When you are given an account on most machines, you will start of with a password assigned to you. However, typically you should change this password as soon as possible. To do this in linux, use the passwd command. Just type passwd at your shell prompt. You will then be asked to type in a new password, and then confirm this password. Remember to choose a sensible password, as covered in Section 1.3

Back to top

8. File compression

You can reduce how much disk a file takes up by compressing the file - 'zipping' the file. Often files for download often come as zipped. In linux, the principal means of compressing a file is through the command gzip. Application of gzip to your file results in the file name being appended with .gz (to signify that it's zipped).


To compress the file "basin-output" you could type at the shell prompt
gzip basin-output
When you hit return, your file basin-output should have been converted into basin-output.gz. Note that this file is now not in "human-readable" format.

To uncompress a file that has a .gz suffix, use the gunzip command.


To inflate the file "basin-output.gz" you could type at the shell prompt
gunzip basin-output.gz
When you hit return, your file basin-output.gz should have been converted into basin-output.

Putting it into Practice:

Read the man page for the gzip command. What is the connection between the zcat and gzip commands?

There may be occassions when you have to unzip a file that was compressed in Microsoft format. In this case, you need to uncompress using the unzip command.