0% found this document useful (0 votes)
49 views

Linux Tutorial

This document provides a quick tutorial on Linux. It covers Linux history, features, getting started, basic commands for working with files and directories, editors, and accessing distant hosts. The document includes sections on Linux and Unix history, logging in, basic commands for file manipulation, directory navigation, and more.

Uploaded by

rthilip
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Linux Tutorial

This document provides a quick tutorial on Linux. It covers Linux history, features, getting started, basic commands for working with files and directories, editors, and accessing distant hosts. The document includes sections on Linux and Unix history, logging in, basic commands for file manipulation, directory navigation, and more.

Uploaded by

rthilip
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 22

Quick Linux Tutorial

Contents

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
9.

Basic Commands

1.

Work with File

1. Display File
2. Copy File
3. Rename and/or Move File
4. Remove File
5. Find File
2.

Work with Directories

1. List Contents of the Working Directory


2. Change Working Directory
3. Moving in Directories
4. Make Directory
5. Remove Directory
3. Access Permission of File
4. Some Postfixes of Files
5. Determine File Type
6. Structure of Standard Directories in Unix/Linux
7. 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
10.

Quick Tutorial for Editor vi

Invoking vi
1.
Cursor Movements Commands
2.
Deleting text
3.
File Saving
4.
Replace Mode
5.
What is next
6.
11. Work at a Distant Host

1. Literature You can find a lot of information in

http://www.castrop-
rauxel.netsurf.de/homepages/m.hussmann/linux.html

or

Larry Grienfield: Linux User's Guide

Return to Contents

2. Unix History 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
3. Linux History 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

4. Linux Features
multitasking: several programs running at once
multiusers: several users at the same machine at once
multiplatforms: it runs on many different CPU
5. Return to Contents
6. Getting Started 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:

$login:

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

Attention!

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:

$password:

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

marian:~$

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
7. Termination of a Program Use (usually) keystroke ctrl-c
8. Leaving the System

It depends on the system. Usually by ctrl-d but in a lot of systems you


must use a special commands

logout

or

exit

Return to Contents

9. Password Changing 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

10. Basic commands


1. Work with File
1. Display File 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

2. Copy File 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

3. Rename and/or Move the File 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

4. Remove File 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.

Attention!

Command
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

5. Find File 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 The command

ls

displays the names of all subdirectories and files in


the working (current, actual) directory.

Example:

$ 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.

Example:

$ 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

2. Change Working Directory 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

3. Moving in Directories
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
4. Return to Contents
5. Make Directory 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

6. Remove Directory 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 Example


4.
5.
6. $ ls -l nparal.f
7.
8. -rw-r--r-- 1 vogel user 776
Aug 30 1995 nparal.f
9.

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

10. Some Postfixes of Files

11. Postfix

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)
compressed by JPEG
.jpg
Return to Contents
12. Determine File Type The type of file can be detected by a
command file.

Example:

$ file kvsortrec.f90

kvsortrec.f90: fortran program text

Return to Contents

13. Structure of Standard Directories in Unix/Linux


Directory Meaning
/bin Directory for system command
Directory with special files which enable to work
/dev
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
Files which are being updated during system
/var
running
14. Return to Contents
15. Other Information
1. Wildcards * and ? * 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

2. Input and Output Redirection 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

3. Another Commands and Examples


1. Concatanation

The command cat concatenates files and prints


on the standard output.

Example
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.

Example:

$ 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

4. Manual and Command man

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

11. Quick Tutorial for Editor vi


1. Invoking vi

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

2. Cursor Movements Commands


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

3. Deleting Text
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.

10

11
Yours sicerely
12

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

4. File Saving
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
5. Replace Mode
Very useful is so called replace mode which enables overwrite the existing text.

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

Return to Contents

6. What is next

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

12. Work at a distant host 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:
13.
14.
15. xhost +
16.
17. rlogin hal.ruk.cuni.cz
18.

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

You might also like