[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ 14 ] [ 15 ] [ 16 ] [ 17 ] [ 18 ] [ A ] [ B ] [ C ] [ D ] [ next ]


Debian Tutorial (Obsolete Documentation)
Chapter 4 - The Basics


4.1 The command line and man pages

We've already discussed the command line, that is commands you type after the shell prompt. This section describes the structure of more complicated command lines.

A minimal command line contains just a command name, such as whoami. But other things are possible. For example, you might type:

     man whoami

This command requests the online manual for the whoami program (you may have to press the space bar to scroll through the documentation, or press q to quit). A more complicated example:

      man -k Postscript

This command line has three parts. It begins with the command name, man. Then it has an option or switch, -k, followed by an argument, Postscript. Some people refer to everything except the command name as the parameters of the command. So, options and arguments are both parameters.

Options change the behavior of a command, switching on particular features or functionality. They usually have a - before them. The GNU utilities also have "long forms" for the options; the long form of -k is --apropos. Enter man -h or man --help to get a full list of options for the man command. Every command will have its own set of options, though most have --help and --version options. Some commands are bizarre; tar, for example, does not require the - before its options, for historical reasons.

Anything which isn't an option and isn't the command name is an argument. In this case, Postscript. Arguments can serve many purposes; most commonly, they are filenames that the command should operate on. In this case, Postscript is the word you want man to search for. In the case of man whoami, the argument was the command you wanted information about.

Breaking down the man -k Postscript command line:

Go ahead and type man -k Postscript, and you will see a list of all the manual pages on your system that have something to do with Postscript. If you haven't installed much software, you might see Postscript: nothing appropriate instead.


4.1.1 Describing the command line

Note: This is a skippable section, if you want to move on.

There's a traditional concise way of describing command syntax [4] that you should know. For example, if you type man man to get the manual page about man, you'll see several syntax descriptions beginning with the command name man. One of them will look like this:

      man -k [-M path] keyword ...

Anything in brackets ([]) is an optional unit. So you don't have to use the -M option, but if you do, you must use a path argument. You must use the -k option and the keyword argument. The ... means that you could have more of whatever came before it, so you could look up several keywords.

Let's look at one of the more complex descriptions from the man manual page:

       man  [-c|-w|-tZT  device]  [-adhu7V] [-m system[,...]] [-L
            locale] [-p string] [-M path] [-P pager] [-r  prompt]  [-S
            list] [-e extension] [[section] page ...] ...

There's no need to go through all of this (and don't worry about what it all means), but do pay attention to the organization of the description.

First, clusters of options usually mean you can use one or more of them in different combinations, so -adhu7V means you can also use -h. However, you can't always use all combinations; this description doesn't make that clear. For example, -h is incompatible with other options, but you could do man -du. Unfortunately the description's format does not make this clear.

Second, the | symbol means "or". So you can use either the -c, the -w, or the -tZT options, followed by a device argument.

Third, notice that you can nest the brackets, since they indicate an optional unit. So if you have a section, you must also have a page, since page is not optional within the [[section] page] unit.

There's no need to memorize any of this, just refer to this section as you read documentation.


4.2 Files and Directories


4.2.1 Introduction to files

Files are a facility for storing and organizing information, analagous to paper documents. They're organized into directories, which are called folders on some other systems. Let's look at the organization of files on a Debian system:

/

A simple / represents the root directory. All other files and directories are contained in the root directory. If you are coming from the DOS/Windows world, / is very similar to what C: is for DOS, that is the root of the filesystem. A notable difference between DOS and Linux however, is that DOS keeps several filesystems: C: (first hard disk), A: (first floppy disk), D: (either CD-ROM or second hard disk) while Linux has all its files organized above the same / root. See mount and /etc/fstab, Section 13.2 for more details.

/home/janeq

This is the home directory of user "janeq". Reading left to right, to get to this directory you start in the root directory, enter directory home, then enter directory janeq.

/etc/X11/XF86Config

This is the configuration file for the X Window System. It resides in the X11 subdirectory of the /etc directory. /etc is in turn a subdirectory of the root directory, /.

Things to note:

Don't worry if all this isn't completely clear yet. There are many examples to come.


4.2.2 Using files: a tutorial

To use your system you'll have to know how to create, move, rename, and delete files and directories. This section describes how to do so with the standard Debian commands.

The best way to learn is to try things. As long as you aren't root (and haven't yet created any important personal files), there's nothing you can mess up too seriously. Jump in --- type each of these commands at the prompt and press enter:

  1. pwd

    One directory is always considered the current working directory for the shell you're using. You can view this directory with the pwd command, which stands for Print Working Directory. pwd prints the name of the directory you're working in --- probably /home/yourname.

  1. ls

    ls stands for "list", as in "list files". When you type ls, the system displays a list of all the files in your current working directory. If you've just installed Debian, your home directory may well be empty. If your working directory is empty, ls produces no output, since there are no files to list.

  1. cd /

    cd means Change Directory. In this case, you've asked to change to the root directory.

  1. pwd

    Verify that you're working in the root directory.

  1. ls

    See what's in /.

  1. cd

    Typing cd with no arguments selects your home directory as the current working directory --- /home/yourname. Try pwd to verify this.

Before continuing, you should know that there are actually two different kinds of filename. Some of them begin with /, the root directory, such as /etc/profile. These are called absolute filenames because they refer to the same file no matter what your current directory is. The other kind of filename is relative.

Two directory names are used only in relative filenames: . and ... The directory . refers to the current directory and .. is the parent directory. These are "shortcut" directories. They exist in every directory. Even the root directory has a parent directory --- it's its own parent!

So filenames which include . or .. are relative, because their meaning depends on the current directory. If I'm in /usr/bin and type ../etc, then I'm referring to /usr/etc. If I'm in /var and type ../etc, then I'm referring to /etc. Note that a filename without the root directory at the front implicitly has ./ at the front. So you can type local/bin or ./local/bin and it means the same thing.

A final handy tip: the tilde ~ is equivalent to your home directory. So typing cd ~ is the same as typing cd with no arguments. Also, you can type things like cd ~/practice/mysubdirectory to change to the directory /home/yourname/practice/mysubdirectory. In a similar way, ~vincent is equivalent to the home directory of the user "vincent", which is probably something like /home/vincent; so ~vincent/docs/debian.ps is equivalent to /home/vincent/doc/debian.ps.

Here are some more file commands to try out, now that you know about relative filenames. cd to your home directory before you begin.

  1. mkdir practice

    In your home directory, make a directory called practice. You'll use this directory to try out some other commands. You might type ls to verify that your new directory exists.

  1. cd practice

    Change directory to practice.

  1. mkdir mysubdirectory

    Create a subdirectory of practice.

  1. cp /etc/profile .

    cp is short for "copy." /etc/profile is just a random file on your system, don't worry about what it is for now. We've copied it to . --- recall that . just means "the directory I'm in now", or the current working directory. So we've created a copy of /etc/profile, and put it in our practice directory. Try typing ls to verify that there's indeed a file called profile in your working directory, alongside the new mysubdirectory.

  1. more profile

    View the contents of the file profile. more is used to view the contents of text files. It's called more because it shows a screenfull of the file at a time, and you press the space bar to see more. more will exit when you get to the end of the file, or when you type q (quit).

  1. more /etc/profile Verify that the original looks just like the copy you made.

  1. mv profile mysubdirectory

    mv stands for "move". We've moved the file profile from the current directory into the subdirectory we created earlier.

  1. ls

    Verify that profile is no longer in the current directory.

  1. ls mysubdirectory

    Verify that profile has moved to mysubdirectory.

  1. cd mysubdirectory

    Change to the subdirectory.

  1. mv profile myprofile

    Note that unlike some operating systems, there is no difference between moving a file and renaming it. Thus there's no separate rename command. Note that the second argument to mv can be a directory to move the file or directory into, or a new filename. cp works the same way.

    As usual, you can type ls to see the result of mv.

  1. mv myprofile ..

    Just as . means "the directory I'm in now", .. means "parent of the current directory", in this case the practice directory we created earlier. Use ls to verify that that's where myprofile is now.

  1. cd ..

    Change directories to the parent directory --- in this case practice, where you just put myprofile.

  1. rm myprofile

    rm means "remove" --- this deletes myprofile. Be careful! Deleting a file on a GNU/Linux system is permanent --- there is no undelete. If you rm it, it's gone, forever. Be carefull! Deleting a file on a GNU/Linux system is permanent --- there is no undelete. If you rm it, it's gone, forever.

  1. rmdir mysubdirectory

    rmdir is just like rm, only it's for directories. Notice that rmdir only works on empty directories --- if the directory contains files, you must delete those files first, or alternatively use rm -r in place of rmdir.

  1. cd ..

    Move out of the current directory, and into its parent directory. Now you can type:

  1. rmdir practice

    This will delete the last remnants of your practice session.

So now you know how to create, copy, move, rename, and delete files and directories. You also learned some shortcuts, like typing simply cd to jump to your home directory, and . and .. to refer to the current directory and its parent, respectively. You should also remember the concept of the root directory, or /, and the alias ~ for your home directory.


4.3 Processes

We mentioned before that GNU/Linux is a multitasking system. It can do many tasks at once. Each of these tasks is called a process. The best way to get a sense of this is to type top at the shell prompt. You'll get a list of processes, sorted according to how much of the computer's processing time they're using. The order will continuously change before your eyes. At the top of the display, there's some information about the system: how many users are logged in, how many total processes there are, how much memory you have and how much you're using.

In the far left column, you'll see the user owning each process. The far right column shows which command invoked the process. You'll probably notice that top itself, invoked by you, is near the top of the list (since anytime top checks on CPU usage, it will be active and using CPU to do the check).

Note all the commands ending in d --- such as kflushd and inetd --- the d stands for daemon[7]. A daemon is a non-interactive process, that is, it's run by the system and users never have to worry about it. Daemons provide services like internet connectivity, printing, or email.

Now press u and give top your user name when it asks. The u command asks to see only those processes belonging to you; it allows you to ignore all the daemons and whatever other people are doing. You might notice bash, the name of your shell. You'll pretty much always be running bash.

Note that column two of the top display shows you the PID, or Process IDentification number. Each process is assigned a unique PID. You can use the PID to control individual processes --- more on that later. Another useful trick: type "?" to get a list of top commands.

You may wonder about the difference between a "process" and a "program" --- in practice people use the terms interchangeably. Technically, the program is the set of instructions written by a programmer, and kept on disk. The process is the working instantiation of the program kept in memory by Linux. But it's not that important to keep the terms straight.

Much of your interaction with a computer involves controlling processes. You'll want to start them, stop them, and see what they're up to. Your primary tool for this is the shell.


4.4 The shell

The shell is a program that allows you to interact with your computer. It's called a shell because it provides an environment for you to work in --- sort of a little electronic home for you as you compute. (Think hermit crab.)

The simplest function of the shell is to launch other programs. You type the name of the program you want to run, followed by the arguments you want, and the shell asks the system to run the program for you.

Of course, graphical windowing systems also fill this need. Technically, Windows 95 provides a graphical shell, and the X Window System is another kind of graphical shell --- but "shell" is commonly used to mean "command line shell."

Needless to say, the hackers who work on shells aren't satisfied with simply launching commands. Your shell has a bewildering number of convenient features if you want to take advantage of them.

There are countless different shells available; most are based on either the Bourne shell or the C shell, two of the oldest shells. The original Bourne shell's program name is sh while csh is the C shell. Bourne shell variants include the Bourne Again Shell from the GNU project (bash, the Debian default), the Korn shell (ksh), and the Z shell (zsh). There is also ash, a traditionalist implementation of the Bourne shell. The most common C shell variant is tcsh (the t pays tribute to the TENEX and TOPS-20 operating systems, which inspired some of tcsh's improvements over csh).

Bash is probably the best choice for new users. It is the default, and has all the features you're likely to need. But all the shells have loyal followings; if you want to experiment, install some different shell packages and change your shell with the chsh command. Just type chsh, supply a password when asked, and chose a shell. When you next log in, you'll be using the new shell.


4.5 Managing processes with Bash

Debian is a multitasking system, so you need a way to do more than one thing at once. Graphical environments like X provide a natural way to do this; they allow multiple windows on the screen at any one time. Naturally, Bash (or any other shell) provides similar facilities.

Earlier you used top to look at the different processes on the system. Your shell provides some convenient ways to keep track of only those processes you've started from the command line. Each command line starts a job (also called a process group) to be carried out by the shell. A job can consist of a single process or a set of processes in a pipeline --- more on pipelines later.

Entering a command line will start a job. Try typing man cp and the cp manual page will appear on the screen. The shell will go into the background, and return when you finish reading the manual page (or type q to quit rather than scrolling through the whole thing).

But say you're reading the manual page, and you want to do something else for a minute. No problem. Type C-z while you're reading to suspend the currently foregrounded job, and put the shell in the foreground. When you suspend a job, Bash will first give you some information on it, and then a shell prompt. You will see something like this on the screen:

     NAME
            cp - copy files
     
     SYNOPSIS
            cp [options] source dest
            cp [options] source... directory
            Options:
            [-abdfilprsuvxPR]  [-S backup-suffix] [-V {numbered,exist�
            ing,simple}]   [--backup]   [--no-dereference]   [--force]
            [--interactive] [--one-file-system] [--preserve] [--recur�
            sive]  [--update]   [--verbose]   [--suffix=backup-suffix]
            [--version-control={numbered,existing,simple}] [--archive]
            [--parents] [--link]  [--symbolic-link]  [--help]  [--ver�
            sion]
     
     DESCRIPTION
     --More--
     [1]+  Stopped                 man cp
     $

Note the last two lines. The next-to-last is the job information, and then you have a shell prompt.

Bash assigns a job number to each command line you run from the shell. This allows you to refer to the process easily. In this case, man cp is job number 1, displayed as [1]. The + means that this is the last job you had in the foreground. Bash also tells you the current state of the job --- Stopped --- and the job's command line.

There are many things you can do with jobs. With man cp still suspended, try this:

  1. man ls

    Start a new job.

  1. C-z

    Suspend the man ls job by pressing Control and lowercase z; you should see its job information.

  1. man mv

    Start yet another job.

  1. C-z

    Suspend it.

  1. jobs

    Ask Bash for a display of current jobs:

         $ jobs
         [1]   Stopped                 man cp
         [2]-  Stopped                 man ls
         [3]+  Stopped                 man mv
         $
    

    Notice the - and +, denoting respectively the next-to-last and last foregrounded jobs.

  1. fg

    Place the last foregrounded job (man mv, the one with the +) in the foreground again. If you press the spacebar, the man page will continue scrolling.

  1. C-z

    Re-suspend man mv.

  1. fg %1

    You can refer to any job by placing a % in front of its number. If you use fg without specifying a job, the last active one is assumed.

  1. C-z

    Re-suspend man cp.

  1. kill %1

    Kill off job 1. Bash will report the job information:

         $ kill %1
         [1]-  Terminated              man cp
         $
    

    Bash is only asking the job to quit, and sometimes a job will not want to do so. If the job doesn't terminate, you can add the -9 option to kill to stop asking and start demanding. For example:

         $ kill -9 %1
         [1]-  Killed                  man mv
         $
    

    The -9 option forcibly and unconditionally kills off the job. [8]

  1. top

    Bring the top display back up. Give the u command in top to see only your processes. Look in the right-hand column for the man ls and man mv commands. man cp won't be there since you killed it. top is showing you the system processes corresponding to your jobs; notice that the PID on the left of the screen does not correspond to the job number.

    You may not be able to find your processes because they're off the bottom of the screen; if you're using X, you can resize the xterm to solve this problem.

    Even these simple jobs actually consist of multiple processes, including the man process and the pager more which handles scrolling a page at a time. You may notice the more processes are also visible in top.

You can probably figure out how to clean up the remaining two jobs. You can either kill them (with the kill command) or foreground each one (with fg) and exit it. Remember that the jobs command will tell you the list existing jobs and their status.

One final note: the documentation for Bash is quite good, but it is found in the Info help system rather than the man pages. To read it, type info bash. See Using info, Section 5.2 for instructions on using the info program. Bash also contains a very good summary of its commands accessible by the help command. help displays a list of available topics; more informations about each of them being accessible with the command help topicname; Try to type

     help cd

for example. This will give you details on the -P and -L arguments recognized by cd.


4.6 A few Bash features

This section mentions just a few of the most commonly used Bash features; for a more complete discussion see Using the shell, Chapter 6.


4.6.1 Tab Completion

The Bash shell can guess what filename or command you are trying to type, and automatically finish typing it for you. Just type the beginning of a command or filename, and press TAB. If Bash finds a single unique completion, it will finish the word and put a space after it. If it finds multiple possible completions, it will fill out the part all completions have in common and beep. You can then enter enough of the word to make it unique, and press TAB again. If it finds no completions, it will simply beep.


4.7 Managing your identity

Unix-like systems are multiuser, and so you have your own electronic identity as a user on the system. Type finger yourusername to have a look at some of the information about you that's publically available. To change the name and shell listed there, you can use the commands chfn and chsh. Only the superuser can change your login (username) and directory. You'll notice that it says "No plan" --- a "plan" is just some information you can make available to others. To create a plan, put whatever information you want people to see in a file called .plan --- to do this you'll use a text editor (see Creating and editing text files, Chapter 8). Then finger yourself to see your plan. Others can finger you to see your plan, and to check whether you've received new mail or read your mail.

Note that this finger information is available to the entire Internet by default. If you don't want this, read about configuring inetd and the file /etc/services --- eventually the installation manual will describe this configuration, for now you might try the man pages, or just put nonsense in for your finger information.


[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ 14 ] [ 15 ] [ 16 ] [ 17 ] [ 18 ] [ A ] [ B ] [ C ] [ D ] [ next ]


Debian Tutorial (Obsolete Documentation)

29 Dezember 2009

Havoc Pennington [email protected]