UNIX講習

UNIXシステムとコマンドの紹介
大阪大学 大学院基礎工学研究科
物質創成専攻 未来物質領域

草部 浩一

Webex connection via Linux◼ When you have a network connection via Linux

successfully, …
◼ You can use Webex via “Web applications”,e.g. “firefox”. Some tips will be shown later.

An instruction on X window (ubuntu machine)◼ We use machines operated by a Linux system .
◼ Each user is identified by “user id” & “password”.
◼ Your terminal might start by pushing the monitor button.

User id is ‘cmd’.
cmdパスワード

Please neglect this page
when you have your own
PC & Linux system for
CMD-WS27!

You need password ‘c.m.dworkshop’ to login a terminal machine.
Another password ‘cmdworkshop’ might work to launch your machine.
You have a good ‘日本語’ environment, if you start by choosing it.

ubuntu : the spirit of Ubuntu to the world of computers

Ubuntu is an ancient African word meaning 'humanity to others'.

Two hints for Webex connection◼ Obtain an invitation◼ Click “web-address”

e-mail on Linux!

to get connection

You see the “terminal” icon. Click it.

Click the icon!

When you had
2 terminals, then ⇒Selection of the terminal

Mouse cursor◼ When you want to use a terminal window, please movethe mouse cursor and click the window, so that theterminal is selected.
◼ Then, you will see a blinking cursor ■.

Type “ls” to see your home directory.

◼ Let’s type “ls ↩(enter)”!
◼ Then you will see a list of files and directories.
◼ These files are in your “home directory”.

To start “Log out” or “Shutdown”◼ Type an icon of thesystem setting in thetitle bar. You will seea pull down menu.
◼ You could have alittle different style.
◼ But, it is not so
difficult to find asolution solving yourdemands, once you
get “your style”.

Logout procedure on ubuntu“Log Out” is hiddenin a submenu.

Login : you start connection to the system!

BobUnix on a PCCCLANRC
A user

A user in a Unix system

InternetAlways you would see,

WAN

CAnother Unix system

SSH : Secure Shell

A cryptographical network protocol

This is “a protocol for secure data communication” between two networkedcomputers. It allows us• To connect your terminal PC to another computer,• To “login” in a secure manner,• To execute “remote commands”.

sshUserShell
KernelHardwareUsing “ssh” in the next page,
you can control a remote hostas if you are using it in front of you.
This action is done in a secured manner!

When your machine is connected to the net,

◼ You see the sign of, you would have “thenetwork connection”.
◼ Please try the next page.
◼ If you have difficulty, please see latter pages.

Let’s login “cmd” !
◼ Find your “user id”: stud** (ex. stud07)◼ On a terminal, use “ssh” to log in cmd2 in OU.
◼ $ ssh –Y –l stud** cmd2.phys.sci.osaka-u.ac.jp

Expr. 1
Ex. 1

Expr. 2◼

$ ssh stud**@ cmd2.phys.sci.osaka-u.ac.jp

Ex. 2◼ Your passphrase is “cmdstud**”.

(“**” is same as the two digits in your id of “stud**”.)◼ The typed passphrase is not shown on the screen.
◼ For the second time, no request for passphrase.
◼ “ssh” is a unix command:◼

$ ssh –Y –l “user id” “machine address”

The first time might open a sub-window.

When the connection is successful,

Two methods for ‘authentication’
RSA public key auth.
◼ Double key authentication◼ Security level : highAppearance

Change id (stud**) !

The passphrase will not
be echoed back (not seen).

From cmd2 to rl: Phrase on cmd2 is used.

The passphrase will not
be echoed back (not seen).

Note: the directory shown is “on the local machine to connect the remote machine”.

RSA & DSA, in a nutshell
RSA was invented by Ron Rivest, Adi Shamir, and Leonard Adleman in 1977.
Nowadays, a key length of 4096 bits is used with$ ssh-keygen –t RSA –b 4096
DSA (Digital Signature Algorithm)
provided by NIST in 1991.
$ ssh-keygen –t DSA

An example of ‘ssh-keygen’ :$ ssh-keygen –t RSA –b 4096
Enter file in which to save the key (/home/kabe/.ssh/id_rsa_2nd) :Enter passphrase (empty for no passphrase) :Enter same passphrase again :The public key in id_rsa.pub on the client-host should be saved (added) in.ssh/authorized_keys
in the server-host.

You might have lost connection.

Please ask help!!

Contents in the right panel
might help you.

In consultation with anadvisor, you would solve
the problem and find“connection”!

Command minimum• Typing a UNIX Command• Login• cp : copy a file
• Unpack : tar• Edit a file : emacs• make : create an application• Run• LogoutKey typing for explanation
This is a character automatically shown by
the computer, which is called “a prompt”.
The character (or a set of words) depends
on the setting of the machine.
Finally, you need to type the return key.

$ less test.txt
There is a space.
Type the space key (The long key).
In this case, you may type letters starting from ‘l’.

Caution: type “q”, when you want to stop, end, or quit less.

At first, please type$ cp /home/CMD/teac01/ex.tar .
Space !

Space !

Next, please type

$ tar xvf ex.tar$ cd ex.

To execute a command, type$ less test.txt
Caution: type “q”, when you want to stop, end, or quit less.

This action may be explained as,Purpose : to see test.txt.
目的：test.txtの中を見る.

$ less test.txt

A short manual of “less”• Move▫ “f” : move forward.
▫ “b” : move backward.

• Search▫ “/ [pattern]” : search the pattern.
▫ “n” : search again• Others▫ “q” : quit. (same as :q, :Q, or ZZ.)
▫ “r” : refresh the screen.
▫ “h” : help.

To compile a program,$ makeTo run the program,$ ./diag

Further, you can use,

$ emacs diag.f90 –nw$ cd ..
.
$ ls –laF.
Please see the following pages and “計算機(UNIX)使用法”.

The terminal does hung-up. You can do it.
◼ No character appears for your keystroke, then◼ Type Ctrl + q . Or Ctrl + s may restart the input, when thescroll is stopped.
◼ No prompt (flushing cursor at /home/x60***> ) appears.

Then, you can try one of these.
(When you call cat without arguments.)◼ Ctrl + c (When a command does not stop.)◼ Ctrl + z Then, you can search an unfinished commandusing ‘ps’ command and stop it by ‘kill’. (This action may
be required when Ctrl + c does not work.)◼

Ctrl +d◼ If something wrong with the cursor, then◼ Ctrl + ｊ .

How to start your job?
◼ Many programs are packaged and stored in acompressed file. You will perform un-compression.
Flow of usage
Un-compress
CompileWrite inputs

Run the program

Command in use
tar (tape archive), uudecode
make, ifort (follow your instructor.)emacs, vi
Command made by compilation, qsub

◼ Un-compression of a tar-archived file would be,[stud01@cmd ~]$ tar xvf CMD-test.tar[stud01@cmd ~]$ tar zxvf CMD-test.tgz
For zip file

Edit a file by “gedit” !
◼ If this is the first time, we recommend you toedit a file by “gedit”.

How to use gedit
Put your curser on the head line, then you will find the menu bar.
Key words in “a fortran source file” are highlighted.

gedit on GNOME environment
When you push “Open”,a window appears toselect a file for edit.

Save, Find, etc. in gedit

You can start “Find”
by pushing binoculars.

You can save the buffer
contents to the file.

How to use Emacs (basics)◼ Let’s start Emacs up with new Window.

[stud01@cmd ~]$ emacs &Don’t you find?
◼ In the first page, message tointroduce Emacs is given.
◼ You can start editing a fileby typing Ctrl + x Ctrl + f .
Please insert a file name at
Find file : ~// represents the home directory.

which is shown in a lower subwindow.
◼ You may edit test.txt by[stud01@cmd CMD-test]$ emacs test.txt &which allows you to start
Name of the target file.
Emacs up with the file shown.

Emacs keystroke I : Ctrl + “1 character”
Keycommand actionKeycommand actionC+@

set-mark-command

C+oopen-line

C+amove-beginning-of-line

C+pprevious-line

C+bbackward-char

C+qquated-insert

C+c

mode-specific-command-prefix

C+rinsearch-backward

C+ddelete-char

C+s

isearch-forward

C+emove-end-of-line

C+ttranspose-chars

C+fforward-char

C+u

universal-argument

C+g

keyboard-quit

C+v

scroll-up

C+h

help-command

C+w

kill-region

C+i

indent-for-tab-command

C+xControl-X-prefix

C+j

newline-and-indent

C+yyankC+kkill-line

C+z

iconify-or-deiconify-frame

C+lrecenter-top-bottom

C+_

undo

C+m

newline-and-indent

C+SPC

set-mark-command

C+nnext-lineC+/

undoEmacs keystroke II : Esc + “1 character”
Keycommand action

Keycommand action

Esc+abackward-sentence

Esc+mback-to-indentation

Esc+b

backward-ward

Esc+oface-meny-keymap

Esc+ccapitalize-word

Esc+q

fill-paragraphEsc+dkill-word

Esc+r

move-to-window-line

Esc+e

forward-sentenceEsc+ttranspose-words

Esc+f

forward-word

Esc+u

upcase-word

Esc+g

prefix command

Esc+v

scroll-down

Esc+hmark-paragraph

Esc+w

kill-ring-save

Esc+itab-to-tab-stop

Esc+x

execute-extended-commandEsc+jindent-new-comment-line

Esc+yyank-pop

Esc+kkill-sentence

Esc+zzap-to-char

Esc+l

downcase-word

In addition, we have
Esc,>

Esc,

<

move to the end of buffer
move to the top of bufferEmacs keystroke III : Ctrl + “2 strokes”
Keycommand actionKeycommand action

C+x C+b

list-buffers

C+x b

switch-to-buffer

C+x C+csave-buffers-kill-emacs

C+x d

dired

C+x C+e

eval-last-sexp

C+x i

insert-file

C+x C+f

find-fileC+x k

kill-buffer

C+x TAB

indent-rigidly

C+x oother-window

C+x C+r

find-file-read-only

C+x u

advertised-undo

C+x C+s

save-buffer

C+x z

repeatC+x C+w write-file
C+x 0

delete-window

C+x 1

delete-other-windows

C+x 2

split-window-verticallyC+x 3

split-window-holizontally• You can do copy or cut&paste
using your mouse.
• Command may be called in the
GUI menu line.
• To make completion, please typeＴａｂ, in a middle of writing a word.
• > may be Shift + . .

Modes of vi & some commands
Let’s do start vi up by
Command mode(Just started)[stud01@cmd ~]$ vi newtest.txt

Please typea (append)i (insert), or
O, o (insert a line)

Text mode(You can write!)Push Esc button after
finishing the input.

$ vi newtest.txt

Command mode

ZZ or:w & :qCommand mode
SelectZZ (write & quit) or:w (write) & :q (quit)a, i, o, O
Text modeEscIf you have a trouble in vi◼ Undo a command just done：

In the command mode (If you are in text mode,type Esc and then) push ‘u’ (undo).
◼ Re-flesh the screen ：Push Ctrl + l in the command mode.
◼ If you did some unwished operations：Type ‘1P’ in the command mode.
◼ If you cannot find a way by doing somesolutions above, please consult instructors(teachers & tutors).

Example of “less .bashrc”◼ Let’s look at contents of a file. Check file lists by “ls –laF.”-rw-r--r-- 1 stud01 cmd 124 Feb 15 19.34 .bashrc...
◼ You can use “cat” to see the contents.

[stud01@cmd ~]$ cat .bashrc◼ You can use “less” command to see the contents of a file.

[stud01@cmd ~]$ less .bashrc◼ Type “q” to end the less command, after checking the contents.
# .bashrc# User specific aliases and functions# Source global definitions
if [ -f /etc/bashrc ]; then. /etc/bashrc
fi.bashrc (END)

Please use “man” command to find
why people use “less.”[stud01@cmd ~]$ man less[stud01@cmd ~]$ man more
Which would you like “more” or “less”?

Thanks a lot.
K. Kusakabe