UNIX講習

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

草部 浩一

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パスワード

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

You see the “terminal” icon. Click it.

Click the icon!

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.

このコンピュータについて
Ubuntuのヘルプシステム設定アカウントのロック/切り替え… Ctrl+Alt+L◼ You could have a

ゲストセッション

little different style.
◼ But, it is not so
difficult to find asolution solving yourdemands, once you
get “your style”.

cmdcmdesログアウト…
サスペンド
シャットダウン…

✔

Login : you start connection to the system!

BobUnix on a PCCCLANRCA user

A user in a Unix system

InternetAlways you would see,WANCAnother Unix system

SSH : Secure ShellA 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”.

ssh
UserShell
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◼ $ ssh stud**@ cmd2.phys.sci.osaka-u.ac.jp◼ 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”

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

Change id (stud**) !

Appearance[teac01@rl ~]$ ssh –Y –l teac01 cmd2 [teac01@cmd2 ~]$ ssh –Y –l teac01 rl
Enter passphrase for key

Enter passphrase for key‘/home/CMD/teac01/.ssh/id_rsa’:‘/home/CMD/teac01/.ssh/id_rsa’:

The passphrase will notecho back (not seen).

The passphrase will notecho 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 the usage of ‘ssh-keygen’ :$ ssh-keygenEnter file in which to save the key (/home/CMD/teac01/.ssh/id_rsa) :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.

Ethernetネットワーク
切断されていますYou need to change this sign,and have the connection.

Wi-Fiネットワーク

Choose ! 切断されています
odins-1x

Buffalo-G-95C0

odins-wlan

Buffalo-G-A85A

odins-visitor-1x

eduloamodins-visitor-wlan

Guest
その他のネットワーク▶

For odins-wlan or odins-visitor-wlan
You need to open “Firefox” by pushing. Then you might be asked to input

your ID and Password for “ODINS”.
For user having “大阪大学個人ID”,choose “odins-wlan”.

For user having “ビジターID”,
choose “odins-visitor-wlan”.

The above images for the login windows might be renewed.

When the connection is successful,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 bythe computer, which is called “a prompt”.
The character (or a set of words) dependson 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 maybe 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-line

C+/

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-paragraphEsc+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 ddired

C+x C+eeval-last-sexp

C+x iinsert-file

C+x C+ffind-file

C+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 theGUI 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