4.1. Using the Command Line
Many system management tasks can be performed using either of the graphical user interfaces provided with Fedora (i.e., GNOME or KDE). However, most power users prefer the command line for system management work because they find it faster, more consistent between different versions of Linux, and easier to access remotely. The command line is also called a shell prompt, because the commands are processed by a program called a shell; the standard shell on a Fedora system is the Bourne-again shell (bash).
4.1.1. How Do I Do That?
If you are logged in to the system through the graphical user interface, access the command line through the terminal program. Select the menu option ApplicationsAccessoriesTerminal (SystemTerminal in KDE), or right-click on the desktop background and select Konsole under KDE.
If you have logged in to the system through a character-mode login screen or an SSH login, you will automatically be presented with a command line.
22.214.171.124. Understanding the shell prompt
This message is an invitation to enter a command. It shows the name of the user (chris), the computer being used (concord2), and the current working directory within the filesystem (~, meaning the user's home directory). The last character of the prompt, $, indicates that this is a normal user's prompt, as opposed to the system administrator's prompt, which ends with #.
126.96.36.199. Entering commands
To enter a command, simply type it, and then press Enter to execute it. The output from the command will appear after the command (scrolling the screen if necessary), and when the command is done a new prompt will be printed.
To edit a command line, use the left and right arrow keys to position within the line, and the Backspace and Delete keys to delete characters to the left or right of the cursor, respectively. To insert text, simply type it. You can press Enter with the cursor located anywhere on the line to execute the command. Other editing keys are available; Table 4-1 shows the most useful ones.
188.8.131.52. Accessing previous commands
You can scroll through the history of previously entered commands using the up and down arrow keys. This enables you to easily re-enter a command, either exactly as you previously entered it or after editing.
You can also search for a previous command by pressing Ctrl-R (for reverse search) and then typing a few characters that appear in the command. For example, if you had at some previous point typed cat /etc/hosts and you pressed Ctrl-R and typed hos, the cat /etc/hosts command would appear (providing that no intervening commands contained the letter sequence hos).
184.108.40.206. Obtaining a root prompt to enter commands as the superuser
The superuser account, root, is also called the privileged account, because it is not subject to the security restrictions that are applied to regular user accounts. root access is required for many system administration commands. Although it's tempting to use the root account all the time on a single-user computer, it is unwise because Fedora assumes that you know what you're doing and won't ask for confirmation if you enter a dangerous command; it will just go ahead and execute it. If you're using the root account, an incorrect command can cause a lot more damage than the same command executed in a normal account.
Although you can directly log in as a root user, it's usually much safer to take on root privilege only when necessary, using the su (switch user) command:
$ su Password: root-password #
The shell prompt will change to end in a pound sign (#) instead of a dollar sign ($) when you are in root mode. Press Ctrl-D or type exit to drop superuser access and return to your regular shell prompt.
220.127.116.11. Linux error messages
Many Linux commands will output a message only if something goes wrong. For example, if you try to remove a file using the rm command, no message will be displayed if the file is successfully deleted, but an error message will be generated if the file does not exist:
$ rm barbeque rm: cannot remove \Qbarbeque ': No such file or directory
Most error messages start with the name of the command that produced the message.
18.104.22.168. Logging out of a shell prompt
4.1.2. How Does It Work?
The shell prompt is managed by bash, the Bourne-again shell. bash got its name from the fact that it is a successor to the original Unix shell, sh, which is also known as the Bourne shell (after its author, Steve Bourne). bash is a command editor, command interpreter, job controller, and programming language.
When bash receives a command, it splits it into words and uses globbing to expand any ambiguous filenames. bash next checks to see if the first word is a built-in command. If not, it treats it as an external command or program and searches a list of directories to find that program. It executes that program, passing the other words to the program as arguments. Almost all Linux commands are external programs.
4.1.3. What About...
22.214.171.124. ...accessing a character-mode display when the graphical user interface is running?
Fedora is configured to allow you to log in using a character-mode display even if the graphical user interface is running. In fact, you can log in up to six times, using the same or different user IDs.
The key is Virtual Terminals (VTs). There are 12 virtual terminals that can be accessed easily: VT1 through VT6 are configured for character-mode login, VT7 is used for graphical login, and VT8 through VT12 are not normally used.
You can log in on multiple VTs simultaneously and switch back and forth between them. This is particularly useful when you bring up documentation on one VT and enter commands on another.
126.96.36.199. ...finding out where a program is located?
The type, which, and whereis commands all provide information about the location of programs.
type will tell you where a command is located in a verbose way, along with an indication of whether the command location is hashed (stored in the shell for quick reference because the command has already been used recently). If there is more than one command with the same name, the location shown is the first one found using your $PATH:
$ type cat cat is hashed (/bin/cat)
$ which cat /bin/cat
whereis will show you all of the locations for the command (and sometimes there are several, if different versions of the same program are installed), along with the location of its manpage documentation:
$ whereis cat cat: /bin/cat /usr/share/man/man1p/cat.1p.gz /usr/share/man/man1/cat.1.gz
188.8.131.52. ...starting graphical programs?
Programs with a graphical user interface are started in exactly the same way as programs with a character-based user interface. GUI-based programs use the DISPLAY environment variable to determine if a graphical display is available and to connect to that display. Some programs, such as system-config-printer, will automatically start up with a graphical or a character-based user interface according to the type of display that is available.
184.108.40.206. ...quickly entering a single command?
Typing Alt-F2 will open a Run Application dialog (in KDE, it's called Run Command), which enables you to enter a single command and run it. This is most useful for starting graphical programs that aren't on the menu.
You can also add an applet to your panel bar that does the same thing.
220.127.116.11. ...the difference between commands, utilities, applications, and programs?
There isn't any! Linux does not make any distinction between categories of programs.
18.104.22.168. ...using a different shell?
$ chsh Password: bigsecret New shell [/bin/bash]: /bin/csh Shell changed.
The password requested is your normal login password; the change will take effect the next time you log in.
chsh requires that you enter the full pathname of the new shell. To see a list of available shells, use chsh with the -l (list) option:
$ chsh -l /bin/sh /bin/bash /sbin/nologin /bin/ksh /bin/tcsh /bin/csh /bin/zsh
zsh, ksh, and bash each use a syntax related to the original Bourne shell (sh). csh uses a very different syntax, which C programmers often find comfortable.
4.1.4. Where Can I Learn More?