Main index

Introducing UNIX and Linux


Getting started

Overview
Using UNIX
      Usernames
      Logging in
Logging out
Commands
      Typing in commands
      Commands and options
Communication with other users
      Email
      Other communication facilities
Files
      The editor Vi
            Vi commands (command mode)
            Vi commands (colon mode)
      Other editors
Input and output
      Scripts
      Here-documents
      Pipes
      Making copies of input and output
      Pagers
Emergencies
Getting help
Summary
Exercises

Commands and options

UNIX commands take the form of a name (such as date), possibly followed by options, and other arguments as required. An option is denoted by a hyphen (-) followed by a single character (itself possibly followed by arguments). For example, the command date can take only one possible option, namely -u. Without this option, the date and time are printed for the local timezone; with option -u the time is converted to UTC (Universal Coordinated time, essentially the same as GMT) thus

date -u
Tue Dec 4 20:10:39 UTC 2001

Information about exactly what machine and operating system version is being used can be found by typing uname (UNIX name). This command will either give a brief (one word) description (typically the name of the operating system), or more detailed information. uname allows several options, including -a (all) to display all information about the system. Note that a company which writes a UNIX operating system will have its own name for it, and will update it periodically; major updates are called releases, minor updates are versions. For instance,

uname
Linux
uname -a
Linux box 2.4.10-4GB #1 Fri Sep 28 17:19:49 GMT 2001 i686 unknown

The output from uname indicates that the operating system is Linux, its (kernel) release is 2.4.10, version #1 Fri Sep 28 17:19:49 GMT 2001, and the name of the machine you are using is box. The hardware being used (i.e. the type of physical machine, as opposed to the operating system, which is software), is an i686. Options -m (machine), -n (nodename), -r (release), -s (system name) or -v (version) can be used to print out part of the information that -a (all) supplies. With no argument, -s is assumed by default. You can combine options, for instance to print out the release and version of your system, and can do so in one of four ways:

uname -r -v
2.4.10-4GB #1 Fri Sep 28 17:19:49 GMT 2001
uname -v -r
2.4.10-4GB #1 Fri Sep 28 17:19:49 GMT 2001
uname -rv
2.4.10-4GB #1 Fri Sep 28 17:19:49 GMT 2001
uname -vr

Try entering uname with the various options. You will be communicating with the machine from a terminal. The command tty displays the name of the terminal you are currently using. If you are using a windowed display, UNIX treats each window as a separate terminal with its own name.

Worked Example

What is the name of the terminal or window you are using?

Solution: Use tty:

tty
pts/1

and the name is pts/1 (or whatever is printed on the screen by tty).

Note that some systems, including Sun's Solaris, have more complex names, such as /dev/pts/1

Another command you can try now is who:

who
chris    pts/1   Dec 3 14:23 (console)
sam      ttyp2   Dec 3 08:38 (console)
jo       pts/4   Dec 3 13:58 (console)

This command lists those people currently logged in to the system by username, together with the terminals they are using and the dates and times they last logged in. On some systems who will also display extra information. In the above example chris logged in at 2.23 pm on Dec 3 to a terminal known as pts/1. This command allows several options, including -u (unused); try typing the command who -u. The output you will get is similar to that for who on its own, except that an extra column of information is given, perhaps:

who -u
chris   pts/1   Dec 3 14:23   .   (console)
sam     ttyp2   Dec 3 08:38 01:03 (console)
jo      pts/4   Dec 3 13:58 00:02 (console)

The extra column indicates idle time - the amount of time a user has not touched the keyboard. So, chris is active at the present moment (a dot is used in place of a time if the user has actually used the system in the previous few seconds). However, sam has been idle for 1 hour and 3 minutes (perhaps sam has forgotten to logout?), and jo has been idle for only two minutes (perhaps thinking about what to do next).


Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck