Originally Published: Tuesday, 12 June 2001 Author: Michael Stutz
Published to: learn_articles_firststep/General Page: 3/5 - [Printable]

The Linux Cookbook: Chapter 2, WHAT EVERY LINUX USER KNOWS

Today's Learn article derived from Chapter Two of the soon to be published Linux Cookbook contains a ton of useful information for the new user. Learn all kinds of useful commands and short-cuts for basic system operation, and then join author Michael Stutz as he answers your questions live in Linux.com Live! Linux.com would like to thank publisher Bill Polluck of No Starch Press for the free use of this material.

Console Basics  << Page 3 of 5  >>


A Linux terminal is a place to put input and get output from the system, and usually has at least a keyboard and monitor.

When you access a Linux system by the keyboard and monitor that are directly connected to it, you are said to be using the console terminal. (Linux systems can be accessed in other ways, such as through a network or via another terminal connected to a serial line; see Chapter 29 Communications, page 307.

Linux systems feature virtual consoles, which act as separate console displays that can run separate login session, but are accessed from the same physical console terminal. Linux systems are configured to have seven virtual consoles by default. When you are at the console terminal, you can switch between virtual consoles at any time, and you can log in and use the system from several virtual consoles at once.

The following recipes explain the basic things you will need to do with virtual consoles.


To switch to a different virutal console, press "Alt"-"Fn", where n is the number of the console to switch to.

  • To switch to the fourth virtual console, press "Alt"-"F4".

This command switches to the fourth virtual console, denoted by 'tty4':

Debian GNU/Linux 2.2 bardo tty4

bardo login:

You can also cycle through the different virtual consoles with the left and right arrow keys. To switch to the next-lowest virtual console (or wrap around to the highest virtual console, if you're at the first virtual console), press "Alt"-"<-". To switch to the next-highest virtual console, press "Alt"-"->".

  • To switch from the fourth to the third virtual console, press:


This keystroke switches to the third virtual console, 'tty3':

Debian GNU/Linux 2.2 bardo tty4

bardo login:

The seventh virtual console is reserved for the X Window System. If X is installed, this virtual terminal will never show a login: prompt, but when you are using X, this is where your X session appears. If your system is configured to start X immediately, this virtual console will show an X login screen.

You can switch to a virtual console from the X Window System using "Ctrl" in conjunction with the usual "Alt" and function keys. This is the only console manipulation keystroke that works in X.

  • To switch from X to the first virtual console, press:



When you are logged in at a virtual console, new lines of text appear at the bottom of the console screen, while older lines of text scroll off the top of the screen.

  • To view this older text, press "Shift"-"PgUp" to scroll back through it.
  • Once you have scrolled back, press "Shift"-"PgDn" to scroll forward through the text toward the most recent text displayed on the console.

The amount of text you can scroll back through depends on system memory.

NOTE: This technique is for scrolling through text displayed in your shell session (see Chapter 3 The Shell, page 35). It does not work for scrolling through text in a tool or application in the console--in other words, you can't use this technique to scroll through text that is displayed by a tool for perusing text files. To scroll through text in an application, use its own facilities for scrolling, if it has any.


Some Keystrokes for manipulation the console display, including those for switching between virtual consoles, are described below. It's a good idea to experiment with these commands until you are comfortable with them, because knowing how to use virtual consoles is basic to using Linux.

"Alt"-"Fn" Switch to virtual console n, where n is a number from 1 to 7 (the default maximum)
"Ctrl"-"Alt"-"Fn" When in X, switch to virtual console n, where n is a number from 1 to 6
"Alt"-"<--" Switch to the next highest virtual console. For example, typing this while in virtual console 4 switches to virtual console 3. Pressing this keystroke in the lowest console wraps around to the highest console.
"Alt"-"-->" Switch to the next lowest virtual console. For example, typing this while in virtual console 4 switches to virtual console 5. Pressing this keystroke in the highest console wraps around to the lowest console.
"Shift"-"PgUp" Scroll back one screen to view previously displayed text.
"Shift"-"PgDn" When viewing previously displayed text, scroll forward one screen.


A tool is a software program that performs a certain function-- usually a specialized, simple task. For example, the hostname tool outputs the system's hostname, and the who tool outputs a listing of the users who are currently logged in. An application is the name given to larger, usually interactive, programs for completing broader kinds of tasks--such as programs for image editing or for word processing.

A tool or application may take any number of options (sometimes called "flags"), which specify a change in its default behavior. It may also take arguments, which specify a file or some other text to operate on. Arguments are usually specified after any options.

A command is the name of a tool or application along with the options and arguments you want to use, if any. Since typing the name of a tool itself is often sufficient to accomplish a desired task, tools alone are often called commands.

Commands are case sensitive; the names of tools and applications are usually in all lowercase letters.

To run (or "execute") a tool or application without giving any options or arguments, type its name at a shell prompt follwed by "Ret".

  • To run the hostname tool, type:
$ hostname "Ret"

The hostname of the system in the example is 'bardo'.

Options always begin with a hyphen character, '-', which is usually followed by one alphanumeric character. To include an option in a command, follow the name of the tool or application with the option. Always separate the tool name, each option, and each argument with a space character.

Long-style options (sometimes called "GNU-style" options) begin with the hyphen characters ('--') and are usually one English word.

For example, many tools have an option, '--version', to output the version number of the tool. (Many tools also have a '--help' option, which outputs a list of options the tool takes; see Recipe 2.8.3 Listing the Usage of a Tool, page 29.)

  • To output the version of the hostname tool, type:
$ hostname --version "Ret"
hostname 2.10

This command outputs the text 'hostname 2.10', indicating that this is version 2.10 of the hostname tool.

Sometimes, an option itself may take an argument. For example, hostname has an option for specifying a file name to use to read the hostname from, '-F'; it takes as an argument the name of the file that hostname should read from.

  • To run hostname and specify that the file 'host.info' is the file to read from, type:
$ hostname -F host.info "Ret"


To change your password, use the passwd tool. It prompts you for your current password and a new password to replace it with. For security purposes, neither the old nor the new password is echoed to the screen as you type it. To make sure that you type the new password correctly, passwd prompts you for your new password twice. You must type it exactly the same way both times, or passwd will not change your password.

  • To change your password, type:
$ passwd "Ret"
Changing password for kurt
Old password: your current password "Ret"
Enter the new password (minimum of 5, maximum of 8 characters)
Please use a combination of upper and lower case letters and numbers.
New password: your new password "Ret"
Re-enter new password: your new password "Ret"
Password changed.

NOTE: Passwords can contain uppercase and lowercase letters, the digits 0 through 9, and punctuation marks; they should be between fie and eight characters long. See Recipe 2.2 Accounts and Privileges, page 18, for suggestions on choosing a good password.


The recipes in this section describe some of the simple commands for finding out who you are currently sharing the system with and what they are doing.


Use whoami to output the username of the user that is logged in at your terminal. This is not as futile a command as one might first think--if you're at a shared terminal, it's useful to determine whether or not it is your account that you're messing in, and for those with multiple accounts on a system, it's useful to see which of them you're currently logged in with.

  • To output your username, type:

$ whoami "Ret"

In this example, the username of the user logged in at this terminal is 'kurt'.


Use who to output a list of all the users currently logged in to the system. It outputs a minimum of three columns, listing the username, terminal location, and time of login for all users on the system. A fourth column is displayed if a user is using the X Window System; it lists the window location of the user's session (see Chapter 4 The X Window system, page 51).

To see who is currently logged in, type:

$ who "Ret"
murky tty1 Oct 20 20:09
dave tty2 Oct 21 14:37
kurt tty3 Oct 21 15:04
kurt ttyp1 Oct 21 15:04 (:0.0)

The output in this example shows that the user murky is logged in on tty1 (the first virtual console on the system), and has been on since 20:09 on 20 October. The user dave is logged in on tty2 (the second virtual console), and has been on since 14:37 on 21 October . The user kurt is logged in twice--on tty3 (the third virtual console), and ttyp1, which is an X session with a window location of '(:0.0)'.

NOTE: This command is for listing the users on the local system; to list the users connected to a different system on the network, or to see more detailed information that a user may have made public about himself, see Recipe 32.4.2 Checking Whether a User is Online, page 351.


The w tool is similar to who, but it displays more detail. It outputs a header line that contains information about the current system status, including the current time, the amount of time the system has been up and running, and the number of users on the system. It then outputs a list of users currently logged in to the system, giving either columns of information for each. These columns include username, terminal location, X session (if any), the time of login, the amount of time the user has been idle, and what command the user is running. (it also gives two columns showing the amount of time the system's CPU has spent on all of the user's current jobs ("JCPU") and foreground process ("PCPU"); processes are discussed in Recipe 2.7 Listing System Activity, page 26, and jobs in Recipe 3.3 Managing Jobs, page 40).

  • To see who is currently logged in and what they are doing, type:

$ w "Ret"
5:27pm up 17:53, 4 users, load average: 0.12, 0.06, 0.01
murky ttyq Oct 20 20:09 17:22m 0.32s 0.32s -bash
dave tty2 14.37 13.00s 2.35 0.07s less foo
kurt tty3 15:04 1:00m 0.41s 0.09s startx
kurt ttyp1 :0.0 15:04 0:00s 21.65s 20.96s emacs

In this example, the command's output shows that the current system time is 5:27 p.m., the system has bee up for 17 hours and 53 minutes, and there are four users currently logged in: murky is logged in at tty1, has been idle for 17 hours and 22 minutes, and is at a bash shell prompt; dave is logged in at tty2, has been idle for 13 seconds, and is using less to peruse a file called 'foo' (see Recipe 9.1 Perusing Text, page 111); and kurt is logged in at two terminals--tty3 and ttyp1, which is an X session. He ran the startx command on tty3 to start his X session, and within his X session, he is currently using Emacs.


Use last to find out who has recently used the system, which terminals they used, and when they logged in and out.

  • To output a list of recent system use, type:

$ last "Ret"

To find out when a particular user last logged in to the system, give his username as an argument.

  • To find out when user kurt last logged in, type:

$ last kurt "Ret"

NOTE: The last tool gets its data from the system file /var/log/wtmp; the last line of output tells how far this file goes back. Sometimes, the output will go back for several weeks or more.

Console Basics  << Page 3 of 5  >>