This chapter looks at some of the basic commands that you need to know to be productive at the command line. You will find out how to get to the command line, and also get to grips with some of the commands used to navigate around the file system. Later on in this book is the "Command-Line Master Class" (Chapter 32), which explores the subject in more depth.
Understanding the Command Line
Hang around Linux users for any length of time and it won't be long before you hear them speak in hushed tones about the command line or the terminal. Quite rightly, too, because the command line offers a unique and powerful way to interact with Linux. However, for the most part, you may never need to access the command line because Fedora offers a variety of graphical tools that enable you to configure most things on your system.
But this is the real world, and sometimes things go wrong, meaning that you might not always have the luxury of a graphical interface to work with. It is in these situations that a fundamental understanding of the command line and its uses can be a real life saver.
It's tempting to think of the command line as the product of some sort of black and arcane art, and in some ways it can appear to be extremely difficult to use. By the end of this chapter, you should at least be comfortable with using the command line and ready to move on to Chapter 32.
More important, however, you will be able to make your way around a command line-based system, which you are likely to encounter if you work within a server environment.
This chapter introduces you to a number of commands, including commands that enable you to do the following tasks:
► Perform routine tasks— Logging in and out, using the text console, changing pass words, listing and navigating directories
► Carry out basic file management— Creating files and folders, copying or moving them around the file system, renaming and ultimately deleting them (if necessary)
► Execute basic system management— Shutting down or rebooting, reading man pages, and using text-based tools to edit system configuration files
The information in this chapter is valuable for individual users or system administrators who are new to Linux and are learning to use the command line for the first time.
TIP
Those of you who have used a computer for many years will probably have come into contact with MS-DOS, in which case being presented with a black screen will fill you with a sense of nostalgia. Do not get too comfy; the command line in Linux is far superior to its distant MS-DOS cousin. Whereas MS-DOS skills are transferable only to other MS-DOS environments, the skills that you learn at the Linux command line can be transferred easily to other UNIX-like operating systems, such as Solaris, OpenBSD, FreeBSD, and even Mac OS X (because it allows you access to a terminal).
Security
One concept you will have to get used to is that of user-based security. By and large, only two types of users will access the system as actual users. The first type is the regular user, of which you created one when you started Fedora for the first time (see Chapter 1, "Installing Fedora"). These users can change anything that is specific to them, such as the wallpaper on the desktop, their personal preferences, and so on. These users are prevented from making changes that will affect other users than themselves, sometimes called systemwide changes.
To make systemwide changes, you need to use the super-user or root account. This is a special-access privilege that gives you complete control over the entire system, with the ability to destroy everything should you so want. If you have installed Linux on your own PC, you automatically have access to the root account as you set it up during the installation. However, it is not unusual for users to not have any access to the root user, especially in corporate environments where security and system stability are of paramount importance.
An example of the destructive nature of root can be found in the age-old example of #rm -rf /
, which erases all the data on your hard drive. You need to be especially careful when working as root; otherwise, you might irreparably damage your system. Don't let this worry you, however, because the root user is fundamental to a healthy Linux system. Without it you would not be able to install new software, edit system configuration files, or do any number of administration tasks. By the end of this chapter, you will feel comfortable working as root and be able to adequately administer your system.
As with most things, Fedora offers you a number of ways to access the command line. You can use the terminal entry in Applications, System Tools, but by far the simplest way is to press Ctrl+Alt+F1. Fedora switches to a black screen and a traditional login prompt that resembles the following:
Fedora Release 8 (Werewolf)
Kernel 2.6.23-0.217.fc8 on an i686
fedora login:
TIP
This is actually one of six virtual consoles that Fedora provides for your use. After you have accessed a virtual console, you can use the Alt key and F1 through F6 to switch to a different console. If you want to get back to the graphical interface, press Alt+F7. You can also switch between consoles by holding the Alt key and pressing either the left or the right cursor key to move down or up a console, such as vt1 to vt2.
Fedora is waiting for you to log in as a user, so go ahead and enter your username and press the Return key. Fedora then prompts you for your password, which you should enter. Note that Fedora does not show any characters while you are typing your password in. This is a good thing because it prevents any shoulder surfers from seeing what you've typed or the length of the password.
Pressing the Return key drops you to a shell prompt, signified by the dollar sign:
andrew@fedora ~]$
This particular prompt tells me that I am logged in as the user andrew on the system fedora and I am currently in my home directory. (Linux uses the tilde as shorthand for the home directory.)
TIP
Navigating through the system at the command line can get confusing at times, especially when a directory name occurs in several different places. Fortunately, Linux includes a simple command that tells you exactly where you are in the file system. It's easy to remember because the command is just an abbreviation of present working directory, so type pwd
at any point to get the full path of your location. For example, typing pwd
after following these instructions shows /home/yourusername,
meaning that you are currently in your home directory.
Using the pwd
command can save you a lot of frustration when you have changed directory half a dozen times and have lost track.
Another way to quickly access the terminal is to go to Applications, Accessories and choose the Terminal entry. Fedora opens up gnome-terminal
, which allows you to access the terminal while remaining in Gnome. This time, the terminal appears as black text on a white background. You can choose to access the terminal this way, or by using the Ctrl+Alt+F1 route; either way you will get to the same place.
Navigating Through the File System
Use the cd
command to navigate through the Fedora file system. This command is generally used with a specific directory location or pathname, like this:
$ cd /usr/share/doc
Under Fedora, the cd command can also be used with several shortcuts. For example, to quickly move up to the parent (higher-level) directory, use the cd command like this:
Читать дальше