Quick Linux Tutorial

Jiri Vogel
Czech Technical University
Department of Technical Mathematics


  1. Literature
  2. Unix History
  3. Linux History
  4. Linux Features
  5. Getting Started
  6. Termination of a Program
  7. Leaving the System
  8. Password Changing
    1. Basic Commands
      1. Work with File
      2. Display File
      3. Copy File
      4. Rename and/or Move File
      5. Remove File
      6. Find File
      1. Work with Directories
      2. List Contents of the Working Directory
      3. Change Working Directory
      4. Moving in Directories
      5. Make Directory
      6. Remove Directory
    2. Access Permission of File
    3. Some Postfixes of Files
    4. Determine File Type
    5. Structure of Standard Directories in Unix/Linux
    6. Other Information
      1. Wildcards * and ?
      2. Input and Output Redirection
      3. Another Commands and Examples
        1. Concatenation
        2. Pipe
        3. Starting and Stopping Processes in the Background
      4. Manual and Command Man
    1. Quick Tutorial for Editor vi
    2. Invoking vi
    3. Cursor Movements Commands
    4. Deleting text
    5. File Saving
    6. Replace Mode
    7. What is next
  9. Work at a Distant Host

  1. Literature
  2. You can find a lot of information e.g. in

    Robert Koretsky at all: Linux, 2001,Addison-Wesley Longmen, Incorporated

    Return to Contents

  3. Unix History
  4. The unfinished development of OS Multics at Bell Laboratories in 1965 left them without a good OS.

    Ken Thopson and Dennis Ritchie decided to sketch out an OS for BL. Ken Thompson implemented it on PDP-7. As a pun on Multix he named the new operating system Unix. A new programming language C was developed for implementation of Unix and 95% of this operating system was written in C - therefore Unix is a very good portable system.

    Return to Contents

  5. Linux History
  6. Linux was written by Linus Torvalds and has been improoved by countless number of people around the word. It was initially developed for small PC.

    The i is pronounced like in "print" and u is like in "rule".

    Return to Contents

  7. Linux Features
  8. Return to Contents

  9. Getting Started
  10. You can login to an UNIX operating system after you had been assigned a username by a system administrator. After a not very complicated procedure, which unfortunately alters according the taste of concrete system administrator you should see something like the following:


    and you should write your username e.g. smith.


    Unix/Linux is case sensitive (as the C language). Username smith is different from Smith

    Stand at easy!

    After entering your username you will be faced with the following:


    and you must written your password. (At first you will be given a password from a system administrator and you can change it at any time.)

    If you have typed your password correctly a prompt will appear. For example:


    or a little detailed prompt


    After that you can apply commands. For example

    $ who
    It appears username of people who just work on the computer. For example:
    spackova   ttyq0        May  5 05:02
    pmayer     ttyq1        May  5 08:11
    vanicek    ttyq2        May  3 18:30
    zchval     ttyq3        May  5 06:52
    wagneros   ttyq6        May  5 07:14
    vskl2309   ttyq8        May  5 07:51
    cajan      ttyq9        May  5 07:56
    barvik     ttyq12       May  5 08:15
    vogel      ttyq13       May  5 08:20
    vogel      ttyq14       May  5 08:20
    michal     ttyq15       Apr 29 11:37
    strakam    ttyq16       Apr 22 13:47
    If you have implemented Linux on your computer you are a system administrator for yourself but you can login to any host which is equiped with Unix. ( See: Work at a Distant Host)

    Return to Contents

  11. Termination of a Program
  12. Use (usually) keystroke ctrl-c

  13. Leaving the System
  14. It depends on the system. Usually by ctrl-d but in a lot of systems you must use a special commands




    Return to Contents

  15. Password Changing
  16. If you want to change your password, you will write the command passwd

    System responds (if your username is smith):

    Changing password for smith
    Old password:
    (You will write your actual password after colon.)
    New password:
    (You will write your new password after colon.)
    Re-type new password:
    (You will repeat your new password after colon.)
    Password changed

    If you write your old password and a new password correctly, the new one becomes valid.

    Return to Contents

  17. Basic commands
    1. Work with File
      1. Display File
      2. If you write the command more and a name of a file then the file will be displayed.

        User can controle the output:

        • press space...the next screen is displayed
        • press enter...the next row is displayed
        • press q.......the command is finished

        Return to Pipe
        Return to Contents

      3. Copy File
      4. The command

        cp file_1 file_2

        copies file_1 to file_2. The both files must be in the same working directory. If they are in various directories, the path must be given.

        Return to Contents

      5. Rename and/or Move the File
      6. The command

        mv file_1 file_2

        moves file_1 to file_2. The both files must be in the same working directory. If they are in various directories, the path must be given. The file_1 is removed from the disk.

        Return to Contents

      7. Remove File
      8. The command

        rm file_a

        removes the file_a from the system at all. If you use wildcard. For example

        rm h*c

        you will remove all files beginning with h and ending with c which are in working directory. If you write

        rm *

        you will erase all files from your working directory. If you write

        rm -i *

        it will be done also but the system will ask for permission before removing each file.

        The command

        rm -r your_file

        causes removing of the directory your_file even if this directory is not empty.


        rm -r /
        will erase all your directories (including not empty directories). If you were a system administrator you should be sent to mad-house; but alas! Too late.

        Stand at easy!

        Return to Remove Directory

        Return to Contents

      9. Find File
      10. The command

        find /usr -name lpr

        finds a file lpr in subdirectores in directory usr.

        Return to Contents

    2. Work with Directories
      1. List Contents of the Working Directory
      2. The command


        displays the names of all subdirectories and files in the working (current, actual) directory.


        $ ls

        BFCPLOT.TMP.gz IMPJET25.CAS TRYSKA21.gz nparal.f ECK.gz IMPJET25.DAT TRYSKA23 par.f.gz ECKERT.CAS.gz IMPJET26.CAS TRYSKA24 parmat.f.gz ECKERT.DAT.gz IMPJET26.DAT TRYSKA25 parts ECKERT.GRD.gz IMPJET27.GRD TRYSKA26 psryi1.xls ECKERTN.DAT.gz Mail alfa22.xls.gz psy23.xls.gz IMPJET13.CAS.gz OSA_X12.gz aly23.xls.gz psy25.xls.gz IMPJET13.DAT.gz OSA_X16 aly24.xls.gz psy26.xls.gz IMPJET14.CAS.gz OSA_X17.gz aly25.xls.gz ptrzj1.xls IMPJET14.DAT.gz OSA_Y12.gz aly26.xls.gz ptz23.xls.gz IMPJET16.CAS.gz OSA_Y16 bin ptz25.xls.gz IMPJET16.DAT.gz OSA_Y17.gz dipsb top.dump IMPJET16.GRD.gz PLUME dispb vmy23_00.xls.gz IMPJET17.CAS.gz PLUMEZJ dispd vmy25_00.xls.gz IMPJET17.DAT.gz PLUMEZJ.CAS dispj vmz23.xls.gz IMPJET18.CAS.gz PLUMEZJ.DAT dispk vmz25.xls.gz IMPJET18.DAT.gz STREAM25.PS.gz dispm wmyi1.xls IMPJET19.CAS.gz TRSKA26.gz dumpster wmyi160.xls IMPJET19.DAT.gz TRYSKA12.gz kont.f.gz wmzj1.xls IMPJET21.CAS.gz TRYSKA13 license.log.gz x IMPJET21.DAT.gz TRYSKA14 matmul.f.gz zp1 IMPJET23.CAS TRYSKA16 mbox IMPJET23.DAT TRYSKA17.gz mulcad $

        If the command ls is written with parameter -l then the command lists contents of the working directory with details.


        $ ls -l

        -rw-r--r-- 1 vogel user 1209041 May 1 13:55 IMPJET24.CAS -rw-r--r-- 1 vogel user 10259798 May 1 20:57 IMPJET24.DAT -rw-r--r-- 1 vogel user 1209041 May 1 13:43 IMPJET25.CAS -rw-r--r-- 1 vogel user 6860385 May 1 23:17 IMPJET25.DAT -rw-r--r-- 1 vogel user 1209041 May 1 14:12 IMPJET26.CAS -rw-r--r-- 1 vogel user 10259798 May 1 14:12 IMPJET26.DAT -rw-r--r-- 1 vogel user 2030624 May 1 11:04 IMPJET27.GRD drwx------ 2 vogel user 22 Apr 9 1997 Mail -rw-r--r-- 1 vogel user 2661 Nov 22 13:48 OSA_X12.gz -rw-r--r-- 1 vogel user 4153 Nov 22 14:01 OSA_X16 -rw-r--r-- 1 vogel user 2399 Nov 22 14:08 OSA_X17.gz -rw-r--r-- 1 vogel user 2299 Nov 22 13:50 OSA_Y12.gz

        Return to Contents

      3. Change Working Directory
      4. The command

        cd try_it

        changes the directory try_it which path is given relative to the working directory. If the working directory is, for example, /home/smith then the working directory will become /home/smith/try_it

        Return to Contents

      5. Moving in Directories
      6. Command Meaning
        cd try_it Change directory
        pwd Print working directory (e.g. /home/smith/try_it)
        cd .. Move to superior directory
        pwd Print /home/smith
        cd /home The absolute path
        pwd Print /home
        cd The system is returned to the user home directory
        pwd Print /home/smith
        Return to Contents

      7. Make Directory
      8. The command

        mkdir my_dir

        makes new directory my_dir (the path is given relative) as a subdirectory of the current directory.

        Return to Contents

      9. Remove Directory
      10. The command

        rmdir your_dir

        removes directory your_dir if it is empty. If you want to remove not empty directory, see.

        Return to Contents

    3. Access Permission of File
    4. Example

      $ ls -l nparal.f
      -rw-r--r--    1 vogel    user         776 Aug 30  1995 nparal.f
      The first column is empty for data and programs or in first column is written character d if the item is directory etc. The next three columns are permissions for the user, the columns 5, 6, 7 for the user's group (in this example the group is called user), and the last three for the rest of the word. The next information in the row is the size of the file (in bytes), the date of the last update, and the name of the file. The next table clarifies the meaning of the letters written from the 2nd to the 10th column:

      Character Meaning
      r Permission for reading
      w Permission for writing
      x File is executable

      If we want to allow people from the user's group to read this file and the rest of the word will be unable even to read this file, we will write the command:

      $ chmod 760 nparal.f
      The access permission looks now like:

      $ ls -l nparal.f
      -rwxrw----    1 vogel    user         776 Aug 30  1995 nparal.
      To understand this you must know that number 1 "allows" and number 0 "suppresses" access permission and you need to know relation between octal and binary numbers:

      Octal scale Binary scale
      0 000
      1 001
      2 010
      3 011
      4 100
      5 101
      6 110
      6 110
      7 111

      Return to Contents

    5. Some Postfixes of Files
    6. Postfix
    7. Meaning
      .c Source program in C language
      .f Source program in Fortran 77
      .f90 Source program in Fortran 90
      .p Source program in Pascal
      .pbm bi-level, black and white image (2 bits per pixel)
      .pgm grayscale (8 bits per pixel)
      .ppm color (24 bits per pixel)
      .jpg compressed by JPEG

      Return to Contents

    8. Determine File Type
    9. The type of file can be detected by a command file.


        $ file kvsortrec.f90
        kvsortrec.f90:  fortran program text
      Return to Contents

    10. Structure of Standard Directories in Unix/Linux
    11. Directory Meaning
      /bin Directory for system command
      /dev Directory with special files which enable to work with pheripheral devices
      /etc System programs and data
      /home User's home directories
      /lib Libraries
      /mnt Directory for mounting of disk pack
      /tmp Directory for temporary data sets
      /usr Other system programs
      /var Files which are being updated during system running

      Return to Contents

    12. Other Information
      1. Wildcards * and ?
      2. * represents any sequence of symbols (0 or more), e.q.
        h* represents how hop htrupp.c high help etc.
        ? represents any symbol; e.q.
        IMPJET2?.DAT represents IMPJET21.DAT IMPJET24.DAT IMJET27.DAT etc.

        Return to Remove File
        Return to Contents

      3. Input and Output Redirection
      4. The command

        p < my_in_file > my_out_file

        causes input to the executable program p from my_in_file and output from the program p to the my_out_file. It is written from the beginning of this file.

        The command

        p < my_in_file >> my_out_file

        has the same meaning but the output is appended to the contents of my_out_file

        Return to Contents

      5. Another Commands and Examples
        1. Concatenation

          The command cat concatenates files and prints on the standard output.

          If in a file A is written The quick brown fox jumped and in a file B is a text over a lazy dog. then command

          	 $ cat A B

          causes the output:

          	 The quick brown fox
          	 jumped over a lazy dog.
          If you write

          $ cat A B > C

          Then the same text is written to the file C.

          Return to Contents

        2. Pipe

          If you write

          ls -l |more

          the operator | connect data of two processes. In this matter contents of the working directory is scrolled according to the process which is defined by the command more.

          Return to Contents

        3. Starting and Stopping Processes in the Background

          If you write for example

          $ p&
          [1] 13456
          the process p starts and it is running on the background. The number which appears in the screen is PID (Process Identification Number). You can do on the foreground other activities but you can stop the process p at any time by a command

          $ kill -9 13456

          which stops the process p before this has been finished normally. You can sometimes work on a distant host computer (see), your process will end in infinite loop (or it seems it lasts too long) and you forgot its PID; you can use command (if your username is for example smith):

          ps -u smith (some systems do ps -u)

          and all your processes are displayed.


          $ ps -u vogel
            PID TTY       TIME COMMAND
           13536 ttyp2     0:00 ps
           13041 ttyp6     0:00 bash
           13525 ttyp2     3:09 p
           12966 ttyp4     0:00 bash
           13128 ttyp5     2:57 netscape
           12985 ttyp5     0:00 bash
           13295 ttyp4     0:03 xterm
           13296 ttyp2     0:01 bash
           12984 ttyp4     0:11 xterm
           13040 ttyp4     0:08 xterm
          Return to Contents

      6. Manual and Command man
      7. The important command of Unix/Linux is a command man.Command man accesses information from the on-line version of Unix/Linux. You can find the description of man by

        man man.

        The whole command is for example:

        man 1 cat

        where 1 is the number of a section. Number 1 need not be written. The number of section is usually mentioned in parentheses behind the referred keywords.

        Return to Contents

  18. Quick Tutorial for Editor vi
    1. Invoking vi
    2. If you write a command

      vi my_file

      you will see the screen with a column of tildes. The editor vi is now in so called command mode.

      The screen looks like:

      The two basic commands are the following:

      i Insert text to the left of cursor
      a Insert text to the right of cursor

      Since you are at the beginning of an empty file it does not matter which of these you type. Write a text:

      Dear Mr Jones,
         Thank you for your letter of January 16th.
      I will be happy to see you on January 30th.
         I suggest you catch the train which leaves 
      Victoria station at 10.40 and reaches Cantebury at 12.03
      I will arrange to meet you at the station. 
         I will look forward to meet you and
      hearing about your proposals.
      						  Yours sicerely
      							  J. B. Show
      Return to Contents

    3. Cursor Movements Commands
    4. You need to be in the command mode. If you do not now what mode is actual, press the buttom esc. This keystroke always turns the editor in the command mode. Then you can move along the screen if you keystrokes the button:

      Keystroke of Doing
      h Cursor is moved one space to the left
      j Cursor is moved one line down
      k Cursor is moved one line up
      l Cursor is moved one space to the right

      Return to Contents

    5. Deleting Text
    6. If you are in command mode then

      Keystroke of Doing
      x Delete one character at the cursor
      dd Delete one line where the cursor is placed

      If you are in command mode and you will write

      :set smd nu

      (where smd means Show MoDe and nu means NUmber),
      you will now see the mode at the right down corner (usually) and all lines are numbered.

      1  Dear Mr Jones,
      3      Thank you for your letter of January 16th.
      4  I will be happ to see you on January 30th.
      5      I sugest you catch the train which leaves
      6  Victoria station at 10.40 and reaches Cantebury at 12.03
      7  I will arrange to meet you at the station.
      8      I will look forward to meet you and
      9  hearing about your proposals.
      11                                      Yours sicerely
      13                                               J. B. Show
      						   INPUT MODE

      Now go to the 6th line - move the cursor underneath the number 2 press letter x. Pres i and write number 3

      Return to Contents

    7. File Saving
    8. You must be in command mode. You can use then several tricks to save the file:

      Keystrokes Doing
      :x Write file to the disk and finish
      ZZ Write file to the disk and finish
      :w Write file to the disk and continue

      Return to Contents

    9. Replace Mode
    10. Very useful is so called replace mode which enables overwrite the existing text.

      Keystrokes Doing
      :r Replace one character over the cursor
      :R Overwrite text until the next action (e.g. keystroke of esc)

      Return to Contents

    11. What is next
    12. The several commands you have learned could be enough for your work. If you will more to know - you can learn to move one text from one place to another in one file or to move a part of the text from one file to another one. In all there are about 150 commands.

      Return to Contents

  19. Work at a distant host
  20. If you want to use your PC with implemented Linux as a terminal of some workstation with the address hal.ruk.cuni.cz, you can write:

    xhost + 
    rlogin hal.ruk.cuni.cz

    This script switches your PC as a terminal to the host computer. You are asked for your password on the host. (If you use command telnet instead of rlogin, you are asked for your username on the host, too.) You must now inform the host about your PC to enable the x-windows to run on your personal computer. It can be done by the script:

    xterm -display jura.fsid.cvut.cz:0 &

    where jura.fsid.cvut.cz is address of your PC.
    It is useful to write the first script as a file (or an alias) on your computer, and the second script as a file (or an alias)on the host.

    Return to Getting Started
    Return to kill
    Return to Contents