Link PayPAL

Monday, May 21, 2007

Tutorial Linux Part IV


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



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.


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



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


# 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


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


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,
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 MODE

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


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


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
:R Overwrite text until the next action (e.g. keystroke of esc)


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.



# 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:

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.

No comments: