unix - the very10 short howto for...

29
UNIX The Very 10 Short Howto for beginners Soon-Hyung Yook March 27, 2015 Soon-Hyung Yook UNIX March 27, 2015 1 / 29

Upload: others

Post on 22-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

UNIXThe Very10 Short Howto for beginners

Soon-Hyung Yook

March 27, 2015

Soon-Hyung Yook UNIX March 27, 2015 1 / 29

Page 2: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

Table of Contents

1 History of Unix

2 What is UNIX?

3 What is Linux?

4 How does Unix work?

5 How to Use it?

Soon-Hyung Yook UNIX March 27, 2015 2 / 29

Page 3: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

History of Unix

How old is UNIX?

Unix originally dates back to 1969with a group at Bell Lab.

The original Unix OS was written inassembler.

In 1973 Ken Thompson and DennisRitchie finally rewrite Unix in theirnew language, C.

The first Unix installation in 1972had 3 users and a 500KB diet. Thompson and Ritchie work at

DEC-PDP 11

Soon-Hyung Yook UNIX March 27, 2015 3 / 29

Page 4: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

What is UNIX?

What is UNIX?

Unix is a multiuser, multitaking operating system (OS).

manage hardware resources.manage directories and file systemsloading, excuting, suspending programs

There are many names of Unix:

Solaris (Sun)AIX (IBM)True64 (Compaq)IRIX (SGI)System V (from AT&T)BSD (from Berkeley)

Soon-Hyung Yook UNIX March 27, 2015 4 / 29

Page 5: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

What is Linux?

What is Linux?

Linux is a clone of the Unix OS written from scratch by Linus Torvalds withassistance from developers around the world.

Developed under the GNU General Public License

The source of Linux is freely available.

There are large number of Linux distributors:

RedHat, Fedora, CentOS, Sicentific LinuxSlackwareDebian, Ubuntu, Mint, LubuntuSUSE, OpenSUSEGentooMandrakeArchKNOPPIX

Soon-Hyung Yook UNIX March 27, 2015 5 / 29

Page 6: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

What is Linux?

Hierarchy of Unix Systems

Soon-Hyung Yook UNIX March 27, 2015 6 / 29

Page 7: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How does Unix work?

Kernel

The kernel is the core of OS

Kernel receives tasks from the shelland performs them.

Users interact with the shell.

Shells

csh, tcshbashksh (Korn shell)sh (Bourne shell)etc.

Everything in Unix is either a file ora process.

A process is an executing programidentified by a unique PID (processidentifier).

make a shell script

Soon-Hyung Yook UNIX March 27, 2015 7 / 29

Page 8: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How does Unix work?

What does the shell do?

The Unix user interface is called the shell.

The shell tends to do 4 jobs repeatedly:

Soon-Hyung Yook UNIX March 27, 2015 8 / 29

Page 9: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

User Interface

Graphical User Interface (GUI): X-Windows.

Command Line Interface (CLI): text based shell.

Basically, the user interacts with UNIX through a shell.

Remote access a shell: using telnet, ssh

X-Windows

X-Windows is the standard graphical layer for Unix systems

Server-client

X supports remote connectivity.

Windows manager/Desktop Environments

WM: fvwm, window maker, open box, owm, etcDE: Gnome, KDE, MATE, XFCE, LXDE, etc.

Soon-Hyung Yook UNIX March 27, 2015 9 / 29

Page 10: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Examples of X-windows systems

GnomeKDE

Soon-Hyung Yook UNIX March 27, 2015 10 / 29

Page 11: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Unix Accounts

User Accounts

To access a Unix system you need to have an account.

Unix account includes:

username and passworduserid and groupidhome directorya default shell preferenceother unimportant informations“/etc/passwd”

Username is a sequence of alphanumeric characters.

Password should be a secrete string that only the user knows.

Not even the system (or administrator) knows a user’s password.Password is encrypted.Strong recommendation: use the special characters and/or numbers.

Soon-Hyung Yook UNIX March 27, 2015 11 / 29

Page 12: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Let’s Login

GDM

Soon-Hyung Yook UNIX March 27, 2015 12 / 29

Page 13: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Remote Login

Use ssh for securityreason.

Windows clientprograms:

puttyXshellother ssh-clientprograms

Soon-Hyung Yook UNIX March 27, 2015 13 / 29

Page 14: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

File Transfer

scp

scp [email protected]:/home/syook/test.txt ./scp ./test.txt [email protected]:/home/syook/tmp

Windows clientprograms:

FilezillaXftpwinscpother scp-clientprograms

Soon-Hyung Yook UNIX March 27, 2015 14 / 29

Page 15: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Unix Directory Tree

Soon-Hyung Yook UNIX March 27, 2015 15 / 29

Page 16: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Directory and Files

Directory

A directory is a special kind of file

Unix uses a directory to hold inforamtion abount other files

The directory often regarded as a container having other files and directories

Folder in MS-windows systems

File name

Each file should have a unique name

The file name in UNIX is case sensitive

Devices are regarded as a file

Pathname

The heirarchical path from the root: Absolute path

The heirarchical path from the current directory: relative path

Soon-Hyung Yook UNIX March 27, 2015 16 / 29

Page 17: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Basic Command

If you are using the X-windows system, run xterm or gnome-terminal, etc.

Soon-Hyung Yook UNIX March 27, 2015 17 / 29

Page 18: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Basic Command

man: display the manual page (RTFM)!

# man ls

ls: displays the names of files and directories.

options l, a, etc.

# ls -l -a

Soon-Hyung Yook UNIX March 27, 2015 18 / 29

Page 19: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Basic Command

permission

Soon-Hyung Yook UNIX March 27, 2015 19 / 29

Page 20: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Basic Command

pwd

where am I?# pwd

chmod

change the permission# chmod 755 test.txt

chown

change the ownership# chown -R syook:statphys test.txt

Soon-Hyung Yook UNIX March 27, 2015 20 / 29

Page 21: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Basic Command

cd

change the directoryabsolute and relative path# cd /usr/bin# cd ../../download

touch

make an empty file# touch 111.txt

mkdir

make a directory# mkdir tmp

Soon-Hyung Yook UNIX March 27, 2015 21 / 29

Page 22: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Basic Command

cp

copy the file# cp *.dat ../data/# cp 111.txt 123.txt

mv

move the fileused to change the name of the file/directory# mv *.dat ../data/# mv 111.txt 123.txt

rm

remove the fileunrecoverable unlike the windows!# rm *.dat# rm 111.txt# rm *

Soon-Hyung Yook UNIX March 27, 2015 22 / 29

Page 23: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Basic Command

passwd

change the password# passwd

ps

display the processes on the machine# ps aux | grep syook

kill

Kill the process# kill -9 [PID]

more (less)

# more test.txt

Soon-Hyung Yook UNIX March 27, 2015 23 / 29

Page 24: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Basic Command

cat

#cat test.txt

wc

count the word# wc -l test .txt

Soon-Hyung Yook UNIX March 27, 2015 24 / 29

Page 25: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Job suspension and background running

Run a backgraound process

use &# xterm &

Suspend a process

use ˆZ (Ctrl+Z)Change the state of suspended job into the background jobjust type bg# bg

Soon-Hyung Yook UNIX March 27, 2015 25 / 29

Page 26: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

pipeline

A pipe line of three programs run on atext terminal (wikipedia).

a set of processes chained by theirstandard streams

the output of each process (stdout)feeds directly as input (stdin) to thenext one

program 1 |program2 |program3

# ls |grep test |less

Soon-Hyung Yook UNIX March 27, 2015 26 / 29

Page 27: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

redirection

The standard streams for input, outputand error (wikipedia).

redirection is a function common tomost command-line interpreters,including the Unix shells.

redirect the starndard streams touser-specified locations

# ls >res.txt# command < file# command1 < infile > outfile# command1 >> file (append to thefile)# command 2> file (save the stderr tothe file)# command 2>&1 (redirect the stderrto stdout)

Soon-Hyung Yook UNIX March 27, 2015 27 / 29

Page 28: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Text Editors

GUI (X-wiondows): anjuta, gedit, nedit, etc.

pretty much like the text editors on MS-Windows

CLI: vi, vim, emacs

We will learn vi in more detail.

Soon-Hyung Yook UNIX March 27, 2015 28 / 29

Page 29: UNIX - The Very10 Short Howto for beginnersfracton.khu.ac.kr/~syook/Lectures/InfoPhys/Unix_Basic.pdf · # bg Soon-Hyung Yook UNIX March 27, 2015 25 / 29 How to Use it? pipeline A

How to Use it?

Logout

logout

# logoutor# exitorˆD (Ctrl+D)

Soon-Hyung Yook UNIX March 27, 2015 29 / 29