The X Window System provides the basis for most graphical
Using various configuration files and commands, you can change nearly every aspect of your graphical environment. Backgrounds can be assigned a single
After reading this chapter, you should feel comfortable working with the GNOME and KDE desktops. The
Although at first it isn’t obvious how to use the shell, with the right help you can quickly learn many of the most important shell features. This chapter is your guide to working with the Linux system commands, processes, and file system from the shell. It describes the shell environment and helps you tailor it to your needs. It also describes how to use and move around the file system.
Throughout this book, there are procedures that require you to use a shell to run commands. How you first get to a shell depends on whether your computer is configured to have a graphical
No desktop — If your Linux system has no GUI (or one that isn’t working at the moment), you log in from a text-based prompt and immediately being working from the shell.
— With the desktop GUI running, you can open a Terminal window (right-click on the desktop, then click
If you are using a shell interface, the first thing you see is the shell prompt. The default prompt for a normal user is simply a dollar sign:
The default prompt for the root user is a
For most Linux systems, the $ or # prompts are preceded by your user name, system name, and current directory
You can change the prompt to display any characters you like. You could use as your prompt the current directory, the date, the local computer name, or any string of
Although there are a tremendous number of features available with the shell, it’s easy to begin by just typing a few commands. Try some of the commands shown in the remainder of this section to become familiar with your current shell environment.
In the examples that follow, the $ or # symbols
When you log in to a Linux system, Linux views you as having a particular identity. That identity includes your user name, group name, user ID, and
To find out information about your identity, use the
$ id uid=501(chris) gid=105(sales) groups=105(sales),4(adm),7(lp)
This shows that the user name is
, which is represented by the numeric user ID (uid)
. Here, the primary group for chris is called
, which has a group ID (gid) of
. Chris also belongs to other groups called
(gid 4) and
(gid 7). These
You can see information about your current login session by using the
command. In the following example, the
$ who -umH NAME LINE TIME IDLE PID COMMENT chris tty1 Jan 13 20:57 . 2013
The output from this
command shows that the user name is
is logged in on
(which is the monitor connected to the computer), and his login session
A shortcut for running the who commands with several options is the w command. Simply type w to see a full listing of who is logged in and what they are doing.
Associated with each shell is a location in the Linux file system known as the current or working directory. As previously mentioned, each user has a directory that is identified as the user’s home directory. When you first log in to Linux, you begin with your home directory as the current directory.
When you request to open or save a file, your shell uses the current directory as the point of reference. Simply give a filename when you save a file, and it will be placed in the current directory. Alternatively, you can identify a file by its relation to the current directory (relative
To find out what your current directory is, type the pwd command:
$ pwd /usr/bin
In this example, the current/working directory is /usr/bin . To find out the name of your home directory, type the echo command, followed by the $HOME variable:
$ echo $HOME /home/chris
At this point, list the contents of your home directory, using the ls command. Either you can type the full path to your home directory to list its contents, or you can use the ls command without a directory name to list the contents of the current directory. Using the -a option to ls enables you to view the hidden files (dot files) as well as all other files. With the -l option, you can see a long, detailed list of information on each file. (You can put multiple single-letter options together after a single dash, for example, -la .)
$ ls -la /home/chris total 158 drwxrwxrwx 2 chris sales 1024 May 12 13:55 . drwxr-xr-x 3 root root 1024 May 10 01:49 .. -rw------- 1 chris sales 2204 May 18 21:30 .bash_history -rw-r--r-- 1 chris sales 24 May 10 01:50 .bash_logout -rw-r--r-- 1 chris sales 30 May 10 01:50 .bash_profile -rw-r--r-- 1 chris sales 124 May 10 01:50 .bashrc drw-r--r-- 1 chris sales 4096 May 10 01:50 .kde -rw-rw-r-- 1 chris sales 149872 May 11 22:49 letter
Displaying a long list ( -l option) of the contents of your home directory shows you more about file sizes and directories. Directories such as the current directory (.) and the directory above the current directory (..) are noted as directories by the letter d at the beginning of each entry. In this case, dot (.) represents /home/chris and two dots (..), which is also referred to as the parent directory, represents /home . The /home directory is owned by root. All other files are owned by the user chris (who belongs to the sales group).
The file or directory names shown on the right are mostly dot (.) files that are used to store GUI properties (
directory) or shell properties (
files). The only non-dot file shown in this example is the one named
. At the beginning of each line are the permissions set for each file. (Permissions and configuring shell property files are described later in this chapter.) Other information in the listing includes the
In addition to being a multiuser operating system, Linux is also a multitasking system. Multitasking means that many programs can be running at the same time. An instance of a running program is referred to as a process . Linux provides tools for listing running processes, monitoring system usage, and stopping (or killing) processes when necessary.
The most common utility for checking running processes is the ps command. With ps , you can see which programs are running, the resources they are using, and who is running them. The following is an example of the ps command:
$ ps au USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 2146 0.0 0.8 1908 1100 ttyp0 S 14:50 0:00 login -- jake jake 2147 0.0 0.7 1836 1020 ttyp0 S 14:50 0:00 -bash jake 2310 0.0 0.7 2592 912 ttyp0 R 18:22 0:00 ps au
In this example, the
option asks to show processes of all users who are associated with your current terminal, and the
option asks that user names be shown, as well as other information such as the time the process started and memory and CPU usage. The concept of terminal comes from the old days, when people worked exclusively from character terminals, so a terminal typically represented a single person at a single screen. Now you can have many "terminals" on one screen by opening multiple Terminal
On this shell session, there isn’t much happening. The first process shows that the user named
logged in to the login process (which is controlled by the root user). The
column shows the name of the user who started the process. Each process is represented by a unique ID number, referred to as a process ID (PID). (You can use the PID if you ever need to kill a runaway process.) The
Many processes running on a computer are not associated with a terminal. A normal Linux system has many processes running in the background. Background system processes perform such
$ ps aux less
I added the pipe ( ) and the less command to ps aux to allow you to page through the many processes that will appear on your screen. Use the spacebar to page through, and type q to end the list. You can also use the arrow keys to move one line at a time through the output. A pipe lets you direct the output of one command to be the input of the next command.
To exit the shell when you are done, either type exit or press Ctrl+D. If you are exiting from your login shell (the shell that started when you first logged in), type logout to exit the shell.
I just showed a few commands designed to familiarize you quickly with your Linux system. Hundreds of other commands that you can try are contained in directories such as /bin and /usr/bin . There are also administrative commands in /sbin or /usr/sbin directories. Many of these commands are described in the remainder of this chapter.