Jiri Vogel
Czech Technical University
Department of Technical Mathematics
Contents
- Literature
- Unix History
- Linux History
- Linux Features
- Getting Started
- Termination of a Program
- Leaving the System
- Password Changing
Basic Commands
Work with File
- Display File
- Copy File
- Rename and/or Move File
- Remove File
- Find File
Access Permission of File Some Postfixes of Files Determine File Type Structure of Standard Directories in Unix/Linux Other Information Work at a Distant Host
You can find a lot of information e.g. in
- Literature
Robert Koretsky at all: Linux, 2001,Addison-Wesley Longmen, Incorporated
The unfinished development of OS Multics at Bell Laboratories in 1965 left them without a good OS.
- Unix History
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.
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.
- Linux History
The i is pronounced like in "print" and u is like in "rule".
- Linux Features
Return to Contents
- multitasking: several programs running at once
- multiusers: several users at the same machine at once
- multiplatforms: it runs on many different CPU
- Getting StartedYou 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 fromSmith
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
$ whoIt 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)
- Termination of a ProgramUse (usually) keystroke
ctrl-c
- Leaving the SystemIt depends on the system. Usually by
ctrl-d
but in a lot of systems you must use a special commands
logout
or
exit
- Password ChangingIf you want to change your password, you will write the command
passwd
System responds (if your username is
smith
):
Changing password for smith
(You will write your actual password after colon.)
Old password:New password:
(You will write your new password after colon.)
Re-type new password:
(You will repeat your new password after colon.)
Password changedIf you write your old password and a new password correctly, the new one becomes valid.
- Basic commands
- Work with File
- Display FileIf 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
- Copy FileThe command
cp file_1 file_2
copies
file_1
tofile_2.
The both files must be in the same working directory. If they are in various directories, the path must be given.
- Rename and/or Move the FileThe command
mv file_1 file_2
moves
file_1
tofile_2.
The both files must be in the same working directory. If they are in various directories, the path must be given. Thefile_1
is removed from the disk.
- Remove FileThe 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.
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!
- Find FileThe command
find /usr -name lpr
finds a file
lpr
in subdirectores in directoryusr
.
- Work with Directories
- List Contents of the Working DirectoryThe command
ls
displays the names of all subdirectories and files in the working (current, actual) directory.
Example:
$ lsIf the commandBFCPLOT.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 $
ls
is written with parameter -l then the command lists contents of the working directory with details.Example:
$ ls -lReturn to Contents-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
- Change Working DirectoryThe 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
- Moving in Directories
Return to Contents
Command Meaning cd try_it
Change directory pwd
Print working directory (e.g. /home/smith/try_it
)cd ..
Move to superior directory pwd
/home/smith
cd /home
The absolute path pwd
/home
cd
The system is returned to the user home directory pwd
/home/smith
- Make DirectoryThe command
mkdir my_dir
makes new directory
my_dir
(the path is given relative) as a subdirectory of the current directory.
- Remove DirectoryThe command
rmdir your_dir
removes directory
your_dir
if it is empty. If you want to remove not empty directory, see.
- Access Permission of FileExample
$ ls -l nparal.f -rw-r--r-- 1 vogel user 776 Aug 30 1995 nparal.fThe 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 calleduser
), 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.fThe 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
- Some Postfixes of Files
- 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) .jpg compressed by JPEG
- Determine File TypeThe type of file can be detected by a command
file
.Example:
$ file kvsortrec.f90 kvsortrec.f90: fortran program textReturn to Contents
- Structure of Standard Directories in Unix/Linux
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
- Other Information
- Wildcards * and ?
*
represents any sequence of symbols (0 or more), e.q.h*
representshow hop htrupp.c high help
etc.?
represents any symbol; e.q.IMPJET2?.DAT
representsIMPJET21.DAT IMPJET24.DAT IMJET27.DAT
etc.Return to Remove File
Return to Contents
- Input and Output RedirectionThe command
p < my_in_file > my_out_file
causes input to the executable program
p
frommy_in_file
and output from the programp
to themy_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
- Another Commands and Examples
- Concatenation
The command
cat
concatenates files and prints on the standard output.Example
If in a fileA
is writtenThe quick brown fox jumped
and in a fileB
is a textover a lazy dog.
then command$ cat A Bcauses 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.
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.
- Starting and Stopping Processes in the Background
If you write for example
$ p& [1] 13456the 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 13456which 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 dops -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 xtermReturn to Contents
Manual and Command man The important command of Unix/Linux is a command
man
.Commandman
accesses information from the on-line version of Unix/Linux. You can find the description ofman
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.
Quick Tutorial for Editor vi
- 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. ShowReturn to Contents
- 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
- 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 andnu
means NUmber),
you will now see the mode at the right down corner (usually) and all lines are numbered.1 Dear Mr Jones, 2 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 MODENow go to the 6th line - move the cursor underneath the number 2 press letter x. Pres i and write number 3
- 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
- Replace Mode
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)
- 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.
Work at a distant hostIf 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.czThis 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 ofrlogin
, 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.