Results 1 to 5 of 5

Thread: Linux LPI 101 - Part I

  1. #1
    Join Date
    Aug 2001

    Linux LPI 101 - Part I

    I'm assuming you have a fully functional Linux-system (with x installed). I'm playing around with RH8 right now, but most of this tutorial should be the same for the major Linux-distributions.

    This tutorial is based on the structure of the LPI-project.


    Assumption: you are logged in to X (the Graphical User Interface) either as root or as a normal user.
    Now press Ctrl-Alt-F1. You'll be taken to a 'virtual console' (tty1), saying something like this:
    Red Hat Linux release 8.0 (Psyche)
    Kernel 2.4.18-19.8.0 on an i686
    localhost login:
    Type 'root', and enter your root-password.
    You'll see something like this:
    Last login: Saturday Jan 26 14:49:51 on tty1
    You have mail.
    [root@localhost root]#
    Warning: 'root' is a power-user/administrator/God on a Linux-system. If you log in as root, the system assumes you know what you're doing. If you don't, there's a big chance you'll screw up your system...

    Our first task will be to add a new user called 'test'.
    To do this, type:
    [root@localhost root]# useradd -m test
    Now we have a user called 'test', but he doesn't have a password yet. To assign a password, type:

    [root@localhost root]#passwd test
    New password:
    To keep it simple, assign the password 'test' to the 'test'.
    The system will tell you the password is too simple: you can ignore that by typing 'test' again and hitting enter.

    Attention: this isn't exactly a good password policy. Linux warns you about it, and for the more serious work, you should take Linux' advice.

    Now let's test this new user:
    Hit ctrl-alt-F2 to open a second virtual console (tty2).
    Enter 'test' both as user and password.
    You can type whatever command there without having to be affraid to harm your system. From now on, we'll be working with this user.

    Summary: you should now have two virtual consoles: tty1 with root logged in, and tty2 with test logged in.

    You can go back to X by pressing Ctrl-Alt-F7.

    1. Part I. LPI 101.

    1.1. Effective use of the Unix command line.

    To leave a shell, type exit


    Once you logged in to Linux, you'll find yourself in your home-directory.
    To see what directory you're in, use pwd:
    [test@localhost test]$ pwd
    Notice that the rootdirectory is known as /
    Notice that Linux is case-sensitive: PWD will give you an error.

    Moving to another directory

    To go to another directory, use cd
    [test@localhost test]$ cd /
    [test@localhost test]$ pwd
    [test@localhost test]$
    cd without options takes you back to your home-directory.

    The actual directory

    The actual directory in Linux is symbolized by .
    [test@localhost test]$pwd
    [test@localhost test]$cd .
    [test@localhost test]$pwd
    [test@localhost test]$
    So cd . doesn't have any effect. The dot can be handy though. More about that later.

    The parent-directory

    Apart from . for the actual directory, Linux also knows .., symbolizing the parent-directory.

    [test@localhost test]$pwd
    [test@localhost test]$cd ..
    [test@localhost test]$pwd
    [test@localhost test]$

    [test@localhost test]$man pwd
    man pwd (man is short for 'manual') will give you a summary of the pwd-command. Type q to exit the man-page(s).

    File overview

    ls will give you an overview of present files.
    [test@localhost test]$ls
    [test@localhost test]$
    As you can see, there are no (visible) files in our test-directory yet.
    [test@localhost test]$ls /
    bin dev home lib misc opt root tmp var
    boot etc initrd lost+found mtn proc sbin usr
    These are the contents of the root-directory.
    Notice the home-directory. To see what users are on your system (ie. users who have a home-directory), use ls /home

    Invisible files

    Invisible files are proceeded by a .. That's the reason you don't see the earlier-mentioned files . and .. with a simple ls.
    To see those invisible files, use ls -a:
    [test@localhost test]$ls -a
    . .bash_history .bash_profile .emacs .kde
    .. .bash_logout .bashrc .gtkrc
    [test@localhost test]$

    The shell/the environment.

    Your prompt is a part of the shell. The shell is a 'buffer' between the user and the rest of the system. The most-used shell on Linux-systems is bash (Bourne Again Shell). Other shells are ksh (Korne Shell), csh (C Shell) en sh (the standard Unix-shell).

    The shell knows a so-called environment. The environment contains a lot of variables that influence the shell.
    [test@localhost test]$set
    [test@localhost test]$
    Each line contains a variable, followed by = and the contents of the variable. It's common use to use capitals for those variables.
    You can set your own variables:
    [test@localhost test]$TEST=negative
    [test@localhost test]$
    You can use those variables at any time by putting a $ in front of them:
    [test@localhost test]$echo $TEST
    [test@localhost test]$
    You can use echo to show the contents of a single variable:
    [test@localhost test]$echo $PATH
    [test@localhost test]$
    The command-history.

    The command-history contains the last 500 commands. You can easily navigate through this list by using the arrow-keys.


    An alias is a 'shorter variant' of a command.
    Let's say you can't get used to using ls instead of DOS's dir, and want the dir-command to do the same thing ls does.
    [test@localhost test]alias dir='ls'
    [test@localhost test]dir /
    bin dev home lib misc opt root tmp var
    boot etc initrd lost+found mtn proc sbin usr
    [test@localhost test]
    Warning: although this might seem as a pretty handy command, aliasing your DOS-commands will only get you weird looks in the Linux-world...

    Some various commands.

    [test@localhost test]write root
    [test@localhost test]
    This will send root a message saying 'Hello!'. You can check this by changing to tty1 (Ctrl-Alt-F1):
    [root@localhost root]#
    Message from test@localhost.localdomain on tty2 at 16.15...
    <ctrl-D> is the EOF (End of File)-character.


    w will display the current users of the system, and what they are doing:
    [test@localhost test]w
    5:02pm  up  2:36,  3 users,  load average: 0.02, 0.02, 0.00
    USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU  WHAT
    root     tty1     -                 4:15pm   44:54   0.01s  0.01s  -bash
    test     tty2     -                 3:24pm   46:49   0.03s  0.03s  -bash
    neg      :0       -                 2:29pm     ?     0.00s   ?     -
    [test@localhost test]

    whoami is not a command to combat an identity-crisis, but a way to figure out under what username you're currently logged in:
    [test@localhost test]whoami
    [test@localhost test]
    type is a way to figure out where a certain file is located:
    [test@localhost test]type ls
    ls is /bin/ls
    [test@localhost test]
    More likely, you'll get something like this on RH 8:
    [test@localhost test]type ls
    ls is aliased to `ls --color=tty'
    [test@localhost test]
    [test@localhost test]type pwd
    pwd is a shell builtin
    [test@localhost test]
    This command tries to take a guess at what kinda file something is:
    [test@localhost test]file /etc/passwd
    /etc/passwd: ASCII text
    [test@localhost test]
    1.2. Editing text.

    The vi-editor

    Vi is the standard Linux-editor. Vi is short for visual, but don't get your hopes too high: vi is very primitive...

    Vi has two different modes: the command-mode and the input-mode.

    The command-mode:
    Commands are preceeded by a ::
    :w --> write the changes to a file
    :q --> exit vi
    :q! --> exit vi without saving
    :wq --> write and exit
    :$ --> jump to the end of the file

    Let's do a little exercise:
    [test@localhost test]vi file1
    Hit the esc-key to enter the command-mode, then type :i - this will take you to insert-mode.
    Enter some random text, then hit esc to go to command-mode again, and type :wq to save the file and exit vi.

    Remark: make sure you're in your own home-directory before trying this.
    Type ls and you should see your newly-created text-file.

    cat is a primitive browser:
    [test@localhost test]cat file1
    [test@localhost test]
    tac is the opposite of cat and will do what one could expect: display the contents of a file starting with the last line.

    more is used for files that take up more than one screen:
    [test@localhost test]more file1
    [test@localhost test]
    less is a powerfull alternative to more (Less is more, I guess?): it allows you to browse a file by using the arrow-keys.

    tail displays the last 10 lines of a file.

    head displays the first 10 lines of a file.
    You can change that number by using this syntax: head -n x file where x is the number of lines to be displayed.

    wc is short for word count:
    [test@localhost test]wc test1
    4       3      22 test1
    [test@localhost test]
    where 4 is the number of lines, 3 the number of words and 22 the number of letters in test1.

    grep is a search-function: it'll search a file for a string:
    [test@localhost test]grep ing test1
    [test@localhost test]
    sort is a sort-function: in its basic form, it'll sort a file starting from the most left text.

    od without options will give the contents of a file in octal form:
    [test@localhost test]od test1
    0000000 062564 072163 072012 071545 064564 063556 072012 071545
    0000020 062564 062553 005012
    [test@localhost test]
    The option -h will display the hexadecimal form of a file.

    Other commands required for LPI: split, fmt, expand, paste, join, pr, tr and sed.
    Use the man-command to obtain more info on them...

    1.3. File management

    Assumption: you're logged in as 'test' in you are in your own home-directory (/home/test).

    We already know ls and ls -a.
    An other interesting option is ls -l:
    [test@localhost test]ls -l
    total 4
    -rw-rw-r-- 1 test test 22 Jan 26 17:49 test1
    [test@localhost test]
    The first column shows you the user-rights of the file (more on them later), the second column ('1') shows you the links to the file. Next is the owner of the file, and the group the user belongs to. '22' is the length of the file in bytes.

    cp is used to copy files:
    [test@localhost test]cp file1 file2
    [test@localhost test]ls -l
    total 8
    -rw-rw-r-- 1 test test 22 Jan 26 17:49 test1
    -rw-rw-r-- 1 test test 22 Jan 26 17:52 test2
    [test@localhost test]
    Warning: the standard cp will NOT prompt you if it's about to overwrite a file. The option -i takes care of that.

    mv is used to move a file.
    [test@localhost test]mv file1 file4
    [test@localhost test]
    is equivalent to copying the file.

    mkdir is short for make directory:
    [test@localhost test]mkdir dir1
    [test@localhost test]ls -l
    total 12
    drwxrwxr-r 2 test test 4096 Jan 26 17:54 dir1
    -rw-rw-r-- 1 test test 22 Jan 26 17:49 test1
    -rw-rw-r-- 1 test test 22 Jan 26 17:52 test2
    [test@localhost test]
    the first 'd' indicates we're dealing with a directory.

    rm is used to remove a file.

    Warning: there is no standard 'undelete' function in Linux! Use rm with caution!

    rmdir is used to remove a directory. Without options, it won't remove a non-empty directory. To circumvent this, use rm -r directory.

    Warning: the command rm -r / run as root will definitely remove all files from your system!!!

    Tip: Norton Commander is a well-know DOS-program to take a lot of work out of your hands. Linux has its own equivalent: Midnight Commander.
    You can start it by typing mc.
    Although it's pretty handy, LPI requires you to do everything by hand...

    Output redirection
    [test@localhost test]ls -al > file5
    [test@localhost test]
    will redirect the output of ls -al to a new file, file5.
    Use >> to add the new content to a file.

    Other commands needed for LPI: xargs and tee.

    1.4. Process management.


    Basically, a Linux-system consists of only a few parts: one of them is the kernel, and the other two are files and processes.
    The kernel is the core, with all kinds of processes 'surrounding' it.

    To abort the executing of a program, you can use Ctrl-C
    [test@localhost test]yes 'hello'
    [test@localhost test]
    Foreground processes
    Vi is a nice example: starting vi means starting a second process (the first would be your shell). Vi has a 'controlling terminal' - your keyboard and monitor if you want, therefore it is a foreground process.

    Background processes.
    Background processes are processes without a controlling terminal. You can start a process in the background by adding & at the end of the command.
    [test@localhost test]sleep 5
    [test@localhost test]
    [test@localhost test]sleep 5 &
    [test@localhost test]
    [test@localhost test]
    [1]+ Done	sleep 5
    [test@localhost test]
    sleep 5: 5 seconds will past while nothing happens. After 5 seconds, the prompt comes back.
    Starting the process in the background (by adding &), will make a line of text appear ([1]2102). Hit the enter-button a couple of times, and you'll see the [1]+ Done sleep 5-line appear after 5 seconds.

    Process ID's
    The number in the previous example (2102) is a PID. The kernel uses this ID to control the process.

    jobs will display the processes started from the shell.

    From foreground to background
    Using <Ctrl-Z>, you can move a process from the foreground to the background. You can try it out with vi:
    [1]+ Stopped 	vi
    [test@localhost test]jobs
    [1]+ Stopped 	vi
    From background to foreground
    OK, we have vi running in the background now. But how do we bring it back?
    fg takes care of that:
    [test@localhost test]fg 1
    The number used here (1) is NOT a Process-ID, it's the number jobs uses.
    bg is the opposite of fg and will put a process in the background.

    If you're running a background process and you log out, the shell will terminate the process. You can avoid this with nohup (short for 'no hang-up').
    [test@localhost test]nohup sleep 5000 &
    The sleep-process starts and will keep on running, even if you log out.

    System processes

    ps is used for an overview of processes:
    [test@localhost test]ps
    PID  TTY      TIME     CMD
    2110 tty1     00:00:00 bash
    2136 tty1     00:00:00 ps
    [test@localhost test]
    This gives you an overview of all processes started by you, knowing the shell (bash) and ps.
    From left to right: the Process ID, the terminal related to the process, used CPU-time and the name of the process.
    ps comes with a lot of options: man ps indeed...

    top is not a standard Unix-command, but it is present at most Linux-systems.
    It'll give you a continuous list of processes:
    [test@localhost test]top
    7:08pm  up  4:42,  3 users,  load average: 0.00, 0.04, 0.20
    84 processes: 80 sleeping, 4 running, 0 zombie, 0 stopped
    CPU states:  3.7% user,  0.9% system,  0.0% nice, 95.2% idle
    Mem:   255408K av,  243748K used,   11660K free,       0K shrd,   16860K buff
    Swap:  522072K av,       0K used,  522072K free                  117804K cached
    967 root 5  -10	88276 21M 9004	S <  3.7  8.6  2:53 X
    On top of your screen, you'll see some status-info for your system.
    The third line (CPU states)indicates how much of its time the CPU spends on running user- or system-processes, and how much of the time it's not doing anything ('idle').

    To terminate a process, one can use kill.
    [test@localhost test]sleep 5000 &
    [test@localhost test]ps
     PID  TTY     TIME     CMD
     2146 tty1    00:00:00 bash
     2172 tty1    00:00:00 sleep
     2173 tty1    00:00:00 ps
    [test@localhost test]kill 2172
    [1]+ Terminated sleep 5000
    [test@localhost test]
    Warning: Being a regular user, you're not allowed to influence processes from other users. As root, you're allowed to do anything!
    'God or root, what's the difference? God is more forgiving'...

    What kill basically does, is send a signal to a running process. Standard, it's the TERM-signal. An alternative for TERM is 15
    [test@localhost test]kill -TERM 2172
    [test@localhost test]kill -15 2172
    TERM nicely asks the process to stop.
    You can get an overview of signals with man 7 signal or kill -l
    If a standard kill does not work, the heavy stuff is needed.
    [test@localhost test]sleep 5000 &
    [test@localhost test]kill -sigkill 2198
    [test@localhost test]
    This signal is not dealt with by the process, but more by the kernel. The kernel will remove the process from the system.

    All processes on a Linux-system have a priority. They receive this priority when they are started, but their priority can be changed. The priority of a process should be seen as a delay-factor. A low delay-factor means a high priority, and the other way around. Normally, a process receives priority 0. The value ranges from -20 to 19. A normal user can only lower the priority of a process.
    The commands used to influence priorities are nice and renice.

    nice allows you to lower the priority of a program when you start it. It's called 'nice' because... well, it's very nice to other users to start a program with a low priority
    [test@localhost test]nice sleep 5000 &
    Standard, nice uses a priority of 10.
    Remember: -20 gives a process the HIGHEST priority.

    renice is used to change a processes priority while it's already running.
    [test@localhost test]renice -5 2210
    renice: 2210: setpriority: Permission denied
    [test@localhost test]renice 12 2210
    2210: old priority 10, new priority 12
    [test@localhost test]
    With the first command, I tried to give the process a higher priority. Since I'm not root, I'm not allowed to do this.

    That's about it for now
    Coming up: Devices, partities and filesystems; advanced filemanagement; runlevels; user-management; system-management (all of them are LPI 101). After that, I'll continue with LPI 102: PC configuration, Linux install, software-management, kernelmanagement; shellscripts; X; Elementary TCP/IP; PPP; inetd,...

  2. #2
    Join Date
    Dec 2002
    Well done

    Linux LPI 10x | more
    God is Love

  3. #3
    Trumpet-Eared Gentoo Freak
    Join Date
    Jan 2003

    You read my mind what I needed, as a Linux - newbie I really can use this kind of stuff.


    Btw, Dit is nog eens vakwerk...
    Come and check out our wargame-site @
    We chat @ #lobby

  4. #4
    Thanx MaN really a Good Tut. of Basic Linux Cmd's

  5. #5
    Just Another Geek
    Join Date
    Jul 2002
    Rotterdam, Netherlands
    The "standard" /bin/sh shell is actually called the Bourne Shell.. Guess why bash is the Bourne Again SHell
    Oliver's Law:
    Experience is something you don't get until just after you need it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts