Getting Started with the Shell


You can start the shell in a number of ways. The most common is to use a terminal emulator program. As its name suggests, this runs a shell inside a program window on your desktop.

You can start Konsole, the built-in KDE shell emulator, by selecting K menu ® System ® Terminal ® Konsole. Alternatively, you can click the shortcut on the Panel, which is the one with the icon of a sea shell set against a monitor, as shown in Figure 14-1.

image from book
Figure 14-1. The Konsole terminal emulator can be quickly started by clicking the icon on the toolbar.

The first thing you'll see when you start Konsole is a help box offering tips. Your instinct might be to get rid of this and also check the box so that it never reappears, but it actually offers quite a few handy hints.

After you've dismissed the help box, you'll see the terminal window. It will show what's referred to as a command prompt: a few words followed by the following symbol: >. On my test system, this is what I see:

 knthomas@linux:~>

The first part is my username—the user account I created during installation and use to log in to the PC. After the @ sign is the name of the PC, which I also chose when installing SUSE Linux. The name of the PC isn't important on most desktop PCs; it's a legacy from the days of Unix. After the colon is indicated the current directory you're browsing. In this example, the ~ symbol appears instead of an actual path or directory name. This is merely SUSE Linux shorthand for the user's home directory. In other words, wherever I see a ~ on my test PC, I read it as /home/knthomas. After this is a cursor, and this is where you can start typing commands!

Note 

Your PC might be called localhost. This is simply the default name for a computer that Linux uses when it hasn't been told to use anything else.

Running Programs

When we refer to commands at the shell, we're actually talking about small programs. When you type a command to list a directory, for example, you're actually starting a small program that will do that job. Seen in this light, the shell's main function is to simply let you run programs— either those that are built into the shell, such as ones that let you manipulate files, or other, more complicated programs that you've installed yourself.

The shell is clever enough to know where your programs are stored. This information was given to it when you first installed SUSE Linux and is stored in a system variable.

Note 

A variable is the method SUSE Linux uses to remember things like names, directory paths, or other data. There are many system variables that are vital for the running of SUSE Linux.

The information about where your programs are stored, and therefore where SUSE Linux should look for commands you type in, as well as any programs you might want to run, is stored in the PATH variable. You can take a look at what's currently stored there by typing the following:

echo $PATH 

Don't forget that the difference between uppercase and lowercase letters matters to SUSE Linux, unlike with Windows and DOS.

The echo command merely tells the shell to print something on screen. In this case, you're telling it to "echo" the PATH variable onto your screen. On my test PC, this returned the following information:

/home/knthomas/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/ gnome/bin:/opt/kde3/bin:/usr/lib/java/jre/bin

There are actually several directories in that list, and each is separated by a slash.

Don't worry too much about the details right now. The important thing to know is that whenever you type a program name, the shell looks in each of the listed directories in sequence. In other words, when you type ls, the command that will give you a directory listing, the shell will look in each of the directories, starting with the first in the list, to see if the ls program can be found. The first instance it finds is the one it will run.

But what if you want to run a program that is not contained in a directory listed in your PATH? In this case, you must tell the shell exactly where the program is. Here's an example:

/home/knthomas/myprogram

This will run a program called myprogram in the /home/knthomas directory. It will do this regardless of the directory you're currently browsing, and regardless of whether there is anything else on your system called myprogram.

If you're already in the directory where the program in question is located, you can type the following:

./myprogram

So, just enter a dot and a forward slash, followed by the program name.

Getting Help

Of course, there are a lot of tricks you can use to get help at the shell. Each command usually has help built in, which you can query (a little like typing /? after a command when using DOS). This will explain what the command does and how it should be used. For example, you can get some instant help on the ifconfig command by typing this:

ifconfig --help

You'll see the help screen shown in Figure 14-2.

image from book
Figure 14-2. Most commands contain built-in help to give you a clue as to how they're used.

The --help option is fairly universal, and most programs will respond to it, although sometimes you might need to use a single dash. Just type the command along with --help to see what happens. You'll be told if you're doing anything wrong.

Nearly always when you use the help command option, you'll be shown an example of the command in use, along with the range of command options that can be used with it.

In addition, most commands have manuals that you can read to gain a fairly complete understanding of how they work. Virtually every SUSE Linux setup has a set of these man pages, which can be accessed by typing this:

man <command>

However, man pages are often technical and designed for experienced SUSE Linux users who understand the terminology.

There are also info pages, which offer slightly more down-to-earth guides. You can read these by typing this:

info <command>

Some commands aren't covered by the info system, however, in which case you'll be shown the default screen explaining basic facts about how the info command works.

Note that both man and info have their own man and info pages, explaining how they work. Just type man man or info info.

Running the Shell via a Virtual Console

As noted earlier, there are a number of ways to start a shell. The most common way among Linux diehards is via a virtual console. To access a virtual console, press Ctrl+Alt, and then press one of the function keys from F2 through F6 (the keys at the top of your keyboard).

Using a virtual console is a little like switching desks to a completely different PC. Pressing Ctrl+Alt+F1 will cause your GUI to disappear, and the screen to be taken over by a command-line prompt (don't worry; your GUI is still there and running in the background). You'll be asked to enter your username and your password.

Any programs you run in a virtual console won't affect the rest of the system, unless they're system commands and you're logged in as the root user. (As discussed in Chapter 13, one way to rescue a crashed GUI program is to switch to a virtual console, become root user, and attempt to terminate the program from there.)

You can switch back to the GUI by pressing Ctrl+Alt+F7. Don't forget to quit your virtual console when you're finished with it, by typing exit.

image from book
Booting into The Shell

If you're really in love with the shell, you can choose to boot into it, avoiding the GUI completely (although you can later start the GUI by typing startx at the command line).

Booting into the shell is done by altering the current run level. A run level is how the operating mode that SUSE Linux is currently running in is described. Run level 5 is most widely used on desktop PCs and means that SUSE Linux is running with a graphical interface. Run level 3 will put the system in text-only mode, although it's still possible to start a GUI manually. Run level 1 is the single-user mode. When this mode is in force, the networking aspect of SUSE Linux is deactivated, and several other system processes are stopped, too. This lets you fix things. It's a bit like Safe Mode under Windows.

You can change the run level on the fly by typing the following commands:

su - [enter your root password] init <run level no>

The first command, su, makes you temporarily the root user (and ensures you adopt the root user's PATH, so you can run root-only commands). You should be careful what you type when switched to root user, because an error can cause serious damage.

The init command is used to switch to a different run level. Typing init 3 will switch you to run level 3, for example, although beware that this will also mean your GUI is instantly killed, and SUSE Linux won't ask if you want to save your files first!

image from book




Beginning SUSE Linux from Novice to Professional
Beginning SUSE Linux: From Novice to Professional
ISBN: 1590594584
EAN: 2147483647
Year: 2005
Pages: 293
Authors: Keir Thomas

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net