linux 기본 명령어

51
SPARCS 10 박박박 koolvibes Linux 박박 박박박

Upload: perry-emerson

Post on 02-Jan-2016

141 views

Category:

Documents


5 download

DESCRIPTION

Linux 기본 명령어. SPARCS 10 박준성 koolvibes. 로그인. # - root 권한 가진 유저 $ - 일반 유저 passwd [user] – 비밀번호 변경. 2. 운영체제 내부 ( 커널 ) 와 유저 사이에 명령어 인터페이스를 제공 로그인 후 쉘 프롬프트가 나온다 = “shell level” 에 있다 = 명령어를 입력할 수 있다 . echo $SHELL 현재 사용중인 쉘 프로그램의 경로 출력 Linux 에서는 대부분 bash 사용 , csh , tcsh - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Linux  기본 명령어

SPARCS 10

박준성

koolvibes

Linux 기본 명령어

Page 2: Linux  기본 명령어

# - root 권한 가진 유저

$ - 일반 유저

passwd [user] – 비밀번호 변경

2

로그인

Page 3: Linux  기본 명령어

운영체제 내부 ( 커널 ) 와 유저 사이에 명령어 인터페이스를 제공

로그인 후 쉘 프롬프트가 나온다

= “shell level” 에 있다

= 명령어를 입력할 수 있다 .

echo $SHELL

현재 사용중인 쉘 프로그램의 경로 출력

Linux 에서는 대부분 bash 사용 , csh, tcsh

bash – script 만들기가 다른 쉘보다 용이

chsh (change shell)

패스워드 입력 후 쉘 변경 가능

3

Shell

Page 4: Linux  기본 명령어

[command] [argument1] [argument2]…

Command 에 따라 사용 가능한 argument 의 형식 등이

다르다

command 의 동작 방법을 명시하는 option

파일이나 디렉토리의 이름 / 경로

임의의 문자열

Etc…

4

Command

Page 5: Linux  기본 명령어

수많은 명령어를 모두 정확히 기억하기는 어렵다

man [ 명령어 ]

manual

해당 명령어의 매뉴얼 페이지를 보여준다

apropos [ 주제어 ]

= man –k [ 명령어 ]

… 에 관하여

주제어에 관련된 매뉴얼 페이지의 제목을 찾아준다

5

Command

Page 6: Linux  기본 명령어

pwd (print working directory)

cd [path]

change directory

6

Path

path 는 절대주소나 상대주소나 ok

cd 홈 디렉토리로 이동cd . 현재 디렉토리로cd .. 상위 디렉토리로cd - 이전 디렉토리로cd ~ 홈 디렉토리로cd / root 로

Page 7: Linux  기본 명령어

ls (list) – list contents of directories

ls [options] [names]

if no [names] given, current directory

-l (long)

-a (all)

-R (recursive)

7

File/Direc-tory

Page 8: Linux  기본 명령어

cp (copy)

cp [file1] [file2] – file1 을 file2 로 복사

cp [files] [directory] – 여러 파일들을 같은 이름으로

directory 에

복사

directory 복사할 때는 – r 을 사용 (recursive)

mv (move)

mv [sources] [target]

8

File/Direc-tory

Source Target Result

File Name(nonexistent)

Rename

File Existing file Overwrite existing file

Directory Name(nonexistent)

Rename

Directory Existing directory Move directory into ex-isting directory

File(s) Existing directory Move files to directory

Page 9: Linux  기본 명령어

rm(remove)

rm –r : file 이 디렉토리면 recursively 안의 content 모두

지움

mkdir (make directory)

rmdir (remove directory)

9

File/Direc-tory

Page 10: Linux  기본 명령어

10

reading,writing file

cat : 파일들을 읽어 들여 standard output 에 출력

cat ch1 display a file

cat ch1 ch2 ch3 > all combine files

cat note5 >> notes append to a file

-n: 각 행에 번호 매김

more : display the named files on a terminal, one screenful at

a time

options ( 물론 이외에도 많음 )

+n( 숫자 ) n 번째 줄부터 보여줌

+/pattern pattern 이 나오기 두 줄 전부터

보여줌

commands

Space - display next screen

Enter – 한 줄씩

z

d

q - quit

Page 11: Linux  기본 명령어

11

reading,writing file

less : more 보다 풍부한 기능들 ( 이전페이지로 가기 용이 )

방향키 , Page Up, Page Down 사용 가능

space 나 enter , q : more 와 동일한 역할

/pattern 문자열 검색

n 을 눌러서 다음 occurrence, N 을 누르면

반대방향으로

wc (word count) : 파일의 줄 수 , 단어 수 , 바이트 수를 출력

Page 12: Linux  기본 명령어

12

reading,writing file

grep (global regular expression print)

파일 ( 입력하지 않을 경우 표준입력 ) 에서 주어진 정규표현식

(regular expression) 에 해당하는 내용이 들어가는 행 출력

-c : match 된 line 수 (count) 만 출력

-i : ignore uppercase & lowercase distinction

-l : list only the names of files with matches

-v : revert-match. print all lines that don’t match the pat-

tern

Page 13: Linux  기본 명령어

13

regular ex-pression,pattern matching

regular expression(text pattern) = normal characters +

special characters(metacharacters, wildcard characters)

Metacharacters : some are valid for one program but not for

another.Sym-bol

Action

. Match any character

* Match zero or more preceding

^ Match beginning of line

$ Match end of line

\ Escape character following

[ ] Match one from a set

+ Match one or more preceding

? Match zero or one preceding

Page 14: Linux  기본 명령어

14

regular ex-pression,pattern matching

examples

Pattern What does it match?bag The string bag.^bag "bag" at beginning of line or string.bag$ "bag" at end of line or string.^bag$ "bag" as the only text on line.[Bb]ag "Bag" or "bag."b[aeiou]g Second character is a vowel.b[^aeiou]g Second character is not a vowel.

b.g Second character is any character except newline.

^...$ Any line containing exactly three characters.

^\. Any line that begins with a dot.

^\.[a-z][a-z] Same, followed by two lowercase letters (e.g., troff re-quests).

^[^.] Any line that doesn't begin with a dot.

bugs* "bug," "bugs", "bugss", etc."word" A word in quotes."*word"* A word, with or without quotes.[A-Z][A-Z]* One or more uppercase letters.[A-Z]+ Same.

[A-Z].* An uppercase letter, followed by zero or more characters.

[A-Z]* Zero or more uppercase letters.[a-zA-Z] Any letter.[0-9A-Za-z]+ Any alphanumeric sequence.

Page 15: Linux  기본 명령어

15

reading,writing file

touch : update access time & modification time of files

(default current time), 파일이 없으면 새로 생성

vi, emacs : editor

Page 16: Linux  기본 명령어

16

Ownership &Permission

각 파일 / 디렉토리는 3 가지 레벨의 권한을 가진다 Owner/User ( 소유자 )

Group ( 소유 그룹 )

Other ( 그 외 )

각각의 파일 / 디렉토리에게는 owner 와 group 이 있다 .

기본적으로 owner 는 파일을 생성한 유저이고 group 은 그 유저가 속한 기본 group 이다 .

Page 17: Linux  기본 명령어

17

Ownership &Permission

chown (change owner): root 만이 owner 를 바꿀 수 있다 chown [owner] [filename]

chown [:group] [filename]

chown [owner :group] [filename]

chgrp (change group): 모든 유저가 group 을 바꿀 수 있다 단 실행하는 유저가 바꾸는 그룹의 멤버여야 한다

chgrp [group] [target1] [target2]…

changing ownership

Page 18: Linux  기본 명령어

18

Ownership &Permission

chmod (u|g|o|a)(+|-)(r|w|x) files directory... change mode

user(owner), group, others, all

+ 는 권한 추가 , - 는 권한 삭제 , = 는 권한 지정

r 은 read, w 는 write, x 는 execute

chmod ug+rw mydir

mydir 의 owner 와 group 에게 read 와 write 권한을 부여한다 .

chmod a-w myfile

myfile 의 owner, group, other 에게서 write 권한을 제거한다

changing permission

chmod 777 [file or directory](r – 4 , w – 2, x – 1)

Page 19: Linux  기본 명령어

19

Ownership &Permission Note: A fourth digit may precede this sequence. This

digit assigns the following modes:

4 : Set user ID. 이 퍼미션이 설정된 파일은 실행되는 동안 owner 권한을 가진다

2 : Set group ID. 이 퍼미션이 설정된 파일은 실행되는 동안 group 권한을 가진다

1 : Set sticky bit. 이 퍼미션이 설정된 디렉토리 안에 있는 파일은 owner 와 root 만이 삭제할 수 있다 . 일반 파일에서는 무시된다 .

changing permission

setuid 의 예제 : passwdsticky bit 의 예제 : 각 유저의 홈 디렉토리

디렉토리의 퍼미션이 파일의 퍼미션보다 우선순위가 높다

Page 20: Linux  기본 명령어

20

Ownership &Permission

chmod examples

chmod u+x file

chmod 751 file chmod u=rwx,g=rx,o=x file

chmod =r file chmod 444 file chmod a-wx,a+r file

chmod 4755 file

Page 21: Linux  기본 명령어

21

Ownership &Permission

chmod examples

Add execute-by-user permission to file:chmod u+x file

Either of the following will assign read/write/execute permission by owner (7), read/execute permission by group (5), and execute-only permission by others (1) to file:chmod 751 file chmod u=rwx,g=rx,o=x file

Any one of the following will assign read-only permission to file for everyone:chmod =r file chmod 444 file chmod a-wx,a+r file

Set the user ID, assign read/write/execute permission by owner, and assign read/execute permission by group and others:chmod 4755 file

Page 22: Linux  기본 명령어

22

Ownership &Permission

umask (user mask)

파일 / 디렉토리 생성시 부여되는 기본 권한을 설정

단 , 파일은 기본적으로 실행 권한을 가지지 않는다

umask 033 이러면 ,

file : 666 – 033 인 633 이 파일의 기본권한

directory : 777 – 033 인 744 가 디렉토리의 기본권한

changing permission

Display file creation mask or set file creation mask to octal value nnn. The file creation mask determines which permission bits are turned off (e.g.,umask 002 produces rw-rw-r--)

Page 23: Linux  기본 명령어

> file Direct standard output to file.

< file Take standard input from file.

>> file Direct standard output to file; append to file if it already ex-

ists.

n> file Direct file descriptor n to file.

n< file Set file as file descriptor n.

mail mother < my_typed_letter

cat file1 file2 > file3

echo “this is a new line” >> existingfile.txt

myprogram 2> errorsfile

23

Redirect-ion

File De-scriptor Name Typical De-

fault

0 Standard in-put (stdin) Keyboard

1 Standard out-put (stdout) Screen

2 Standard error (stderr) Screen

Page 24: Linux  기본 명령어

24

Pipe | 두 개 이상의 명령어를 ‘파이프’로 연결

cmd1 | cmd2

take standard output of cmd1 as standard input to cmd2

ls -l | less

ls -l 명령어의 출력이 less 명령어의 입력으로 연결된다

현재 작업 디렉토리에 있는 파일 상세정보를 한 페이지씩 넘겨서

볼 수 있다

ps | grep chrome

실행중인 프로세스 목록 중에 chrome 이 들어가는 행을 출력

chrome 의 프로세스 ID 를 한눈에 찾을 수 있다

Page 25: Linux  기본 명령어

25

Process

프로세스 : 컴퓨터 내에서 독립적으로 실행되고 있는 각각의 프로그램 메모리와 디스크 같은 자원은 한정되어 있기에 커널이라는 강력한

프로그램에서 관리한다 .

다른 모든 프로그램은 프로세스이다 .

명령어가 입력되면 , 쉘이라는 프로세스가 새로운 프로세스를 생성한다 . (forking)

쉘과 명령어 프로그램이 독립된 프로세스이기에 쉘은 화면에 , 명령어의 결과는 파일에 출력하도록 할 수 있다 . (Redirection)

각각의 프로세스는 Process ID(pid) 로 구분한다 .

Page 26: Linux  기본 명령어

26

Process 쉘은 프로세스를 foreground 와 background 로 나누어 관리한다 .

Foreground

유저에게 출력되고 입력을 받는 프로세스

명령어는 기본적으로 foreground 로 실행된 후 종료 / background 로 전환된다

Foreground 가 끝난 후에야 새로운 명령어를 받는 쉘 프롬프트가 출력된다 .

Background

유저에게 보여지지 않는다

Foreground 프로세스가 없는 사이사이에 “뒤에서” 실행된다 .

명령어 뒤에 & 를 붙여서 입력하면 background 로 실행된다 .

이와 같이 프로세스를 관리하는 것을 작업 관리 (Job Control), 관리되는 프로세스를 작업 (Job) 이라고 한다 .

Page 27: Linux  기본 명령어

27

Job Con-trol

ls 같은 명령어는 빨리 실행되지만 , 매우 용량이 큰 파일을

옮긴다거나 하는 건 시간이 오래 걸림 . 이럴 때 job 을 background

에서 실행시키게 해서 그 동안 다른 command 를 실행할 수 있다 .

While running a command (job)

ctrl-z : pause/suspend

ctrl-c : kill

Command

Function

fg move a suspended job to the fore-ground

bg continue a suspended job in the background

jobs list active jobs

kill terminate a job

wait wait for background jobs to finish

command & execute command in background

kill %n , kill process id

Page 28: Linux  기본 명령어

28

Process top

CPU 점유율 순으로 정렬되어 프로세스들을 보여줌 ( 갱신 )

Page 29: Linux  기본 명령어

29

Process ps – 실행중인 프로세스 확인 TIME: 프로세스가 사용한 CPU 시간

COMMAND: 프로세스를 실행한 명령어

PID: 프로세스 ID( 번호 )

TTY: 입출력 터미널

Page 30: Linux  기본 명령어

30

Signal Signal( 신호 ) 프로세스간에 의사소통을 위해서 보내는 ‘신호’

ID( 번호 ) 나 Name( 이름 ) 으로 나타낼 수 있다 .

Ctrl+Z 를 누르면 프로세스에 SIGTSTP 이라는 신호가 가서 일시정지된다

Page 31: Linux  기본 명령어

31

Signal 프로세스에 시그널 보내기 kill 계열 명령어 (kill, killall, skill…)

시그널이 명시되지 않으면 15 번 SIGTERM(terminate) 가 가서 프로세스를 죽이므로 kill.

kill [-signal name / -sigid] [jobspec / pid] 작업 혹은 프로세스에 시그널을 보낸다 .

kill 1234

kill -TERM 1234 kill -KILL 1234

kill -15 1234 kill -9 1234

killall [-signal name / -sigid] [command name] 지정된 명령이 실행중인 모든 프로세스에 시그널을 보낸다

killall -KILL httpd

웹 서버 데몬 (httpd) 를 모두 종료

Page 32: Linux  기본 명령어

32

Signal

Page 33: Linux  기본 명령어

33

Signal

Page 34: Linux  기본 명령어

34

Signal

Page 35: Linux  기본 명령어

35

Page 36: Linux  기본 명령어

36

Page 37: Linux  기본 명령어

37

Page 38: Linux  기본 명령어

tar.gz 압축하기

tar cvf filename.tar file1…

gzip filename.tar

tar.gz 한번에 압축하기

tar cvzf filename.tar file1…

tar.gz 압축풀기

gunzip filename.tar.gz

tar xvf filename.tar

tar.gz 한번에 풀기

tar xvzf filename.tar.gz

38

파일 압축 / 풀기

Page 39: Linux  기본 명령어

wget [ 주소 ] : 인터넷에서 파일 다운로드

ssh 아이디 @[ 주소 ] :

secure shell: 네트워크 상의 다른 컴퓨터에

로그인하거나 원격 시스템에서 명령을 실행하고 ,

다른 시스템으로 파일을 복사할 수 있도록 해주는

응용 프로그램 또는 그 프로토콜 (putty : ssh

사용 )

sudo : superuser 권한으로 명령 실행

39

Etc.

Page 40: Linux  기본 명령어

LINUX IN A NUTSHELL

http://www.oreillynet.com/linux/cmd/

http://docstore.mik.ua/orelly/linux/lnut/index.htm

http://linux.about.com/

선배들의 세미나 자료 (cling,noname,boolgom,leopine,…)

EE209 2011 Fall lecture (Prof. Kyungsoo Park)

40

Reference

Page 41: Linux  기본 명령어

실습 !

41

Page 42: Linux  기본 명령어

설명 안했던 것들이 뙇 !!

find xargsawk ``

42

Page 43: Linux  기본 명령어

An extremely useful command for finding particular groups of

files

find descends the directory tree beginning at each pathname

and locates files that meet the specified conditions.

default pathname : current directory

default condition : -print

43

find [pathnames] [conditions]

Page 44: Linux  기본 명령어

An extremely useful command for finding particular groups of

files

find descends the directory tree beginning at each pathname

and locates files that meet the specified conditions.

default pathname : current directory

default condition : -print

44

find [pathnames] [conditions]

Page 45: Linux  기본 명령어

An extremely useful command for finding particular groups of

files

find descends the directory tree beginning at each pathname

and locates files that meet the specified conditions.

default pathname : current directory

default condition : -print

45

find [pathnames] [conditions]

Page 46: Linux  기본 명령어

46

Page 47: Linux  기본 명령어

47

Page 48: Linux  기본 명령어

48

Page 49: Linux  기본 명령어

49

Page 50: Linux  기본 명령어

awk ‘script’ files

script : pattern {procedure}system variable $n : nth field

50

Page 51: Linux  기본 명령어

51