본문 바로가기
국비교육

Linux 2일차

by Diligejy 2019. 5. 24.

1. 

man man : 리눅스에서 제공하는 도움말 

sudo yum install man : 도움말 설치

sudo yum install man-pages-ko : 한글 도움말 페이지 설치

 

ⓐ 실행 프로그램 쉘 명령

ⓑ 시스템 호출 (커널에서 제공하는 내용)

ⓒ 라이브러리 호출 시

ⓓ 특수파일 / dev 하위에 존재하는 파일

ⓔ 파일형식 (/etc/passwd)

ⓕ 게임 

ⓖ 매크로 패키지 등

ⓗ 시스템 관리 등(보통 root)

-a 모든 섹션의 설명서

 

ex) man 1 time

man 2 time

man -a time

 

2. 

계정

passwd : 자신의 암호 변경하는 것

su 사용자이름 : 다른 사용자로 전환된다.

sudo 명령어 : root 권한으로 명령이 실행된다.

 

사용자 조작

passwd 사용자 이름 : 암호변경

useradd(adduser) 사용자 이름 : 사용자 추가

userdel 사용자 이름 : 사용자 삭제

 

3.

ⓐ adduser test : test라는 계정을 확인한다.

 

ⓑ pw를 지정한다.

passwd test

 

ⓒ su로 접속해본다.

su test

 

ⓓ pwd를 확인해본다.

 

4.

userdel 사용자이름 -> 폴더는 놔두고 계정만 지움

userdel -r 사용자이름 -> 폴더는 삭제하고 계정은 놔둠

 

5.

vi /etc/passwd

 

6. 

디렉토리, 파일

pwd : 현재 디렉토리 절대 경로

cd 

cd.. : 상위 디렉토리 이동

cd ~ : 자신의 홈 디렉토리로 이동

cd ~ [사용자명] : 특정 사용자의 홈 디렉토리로 이동

ls

ls -al : 숨겨진 파일을 포함해서 자세하게 출력해준다.

mkdir

rmdir -p

 

ex) mkdir mtest mtest/a mtest/b mtest/c

 

6. 

vi /etc/sudoers (su 권한을 확인 설정 변경)

 

7.

mybig 게정은 sudo권한이 아니기 때문에 계정 생성을 할 수 없다.

sudo권한을 추가하자

[root@localhost 바탕화면] # ls -al /etc/sudoers

[root@localhost 바탕화면] # chmod u+w /etc/sudoers

[root@localhost 바탕화면] # ls -al /etc/sudoers

-rw-r-----. 1. root root 3729 2015-12-08 21:43 /etc/sudoers

[root@localhost 바탕화면] # vi /etc/sudoers

[root@localhost 바탕화면] # source /etc/sudoers

[root@localhost 바탕화면] # sudo vi /etc/shadow

[root@localhost 바탕화면] # su mybig

[mybig@localhost ~] $ sudo adduser Test02

 

8. 파일관리 

touch [파일명] : 파일을 생성한다

cp [원본] [사본] : 복사

mv [원본] [목적지] : 이동

cat : 파일의 내용을 출력한다.

 

9.

[test@localhost ~] $mkdir fileTest02

[test@localhost ~] $mv a.txt fileTest02/

[test@localhost ~] $cp fileTest/b.txt fileTest02

[test@localhost ~] $ls

fileTest fileTest02

[test@localhost ~] $ls fileTest02

a.txt b.txt

[test@localhost ~] $pwd

/home/Test

 

10.

find

find / -name *linux* : linux가 파일명에 포함된 모든 파일을 찾는다.

find -user linux : 소유자가 linux인 파일을 찾는다.

find -perm 755 : 권한이 755인 모든 파일을 찾는다.

grep : 정규패턴 / 파이프를 조합해서 사용할 수 있다.

ex) yum list | grep jdk, ps

 

11.

[명령어] > [파일] : 명령어의 출력을 파일에 저장한다. 덮어쓴다

[명령어] >> [파일] : 명령어의 출력을 파일에 저장한다. 추가한다.

[명령어] < [파일] : 파일에서 표준입력으로 받는다.

 

[Test@localhost ~]$ ls

fileTest fileTest02

[Test@localhost ~] $ cd fileTest

[Test@localhost fileTest] ls

b.txt

[Test@localhost fileTest]$ cat > b.txt

aaaaaaaaaaaaaa

bbbbbbbbbbbbbbbbbb

ccccccccccccccc

[Test@localhost fileTest]$ cat b.txt

[Test@localhost fileTest]$ cat>> b.txt #추가

kkkkkkkkkkkkkkkk

[Test@localhost fileTest]$ cat b.txt

[Test@localhost fileTest]$ cat /etc/passwd

[Test@localhost fileTest]$ cat /etc/passwd | grep my

[Test@localhost fileTest]$ # /etc/passwd | grep hadoop를 c.txt로 저장하고 싶다.

-> [Test@localhost fileTest]$ cat /etc/passwd | grep hadoop > c.txt

[Test@localhost fileTest] $ cat c.txt

[Test@localhost fileTest]$ cat < c.txt > res.txt

[Test@localhost fileTest]$ more /etc/passwd

[Test@localhost fileTest]$ more -5 /etc/passwd

[Test@localhost fileTest]$ head -5 /etc/passwd

[Test@localhost fileTest]$ head -c 100 /etc/passwd

 

grep -A -B -c -i |n

 

12.

[Test@localhost fileTest]$ cat > my

1.apple

2.strawberry

3.watermelon

4.mandarin

5.pear

6.apricot

 

ex)

1. my 파일에서 귤을 포함한 아래 2개의 과일을 찾아라

[Test@localhost fileTest]$ grep -A 2 mandarin my

 

2. 수박을 포함한 위 1개의 과일을 찾아라

[Test@localhost fileTest]$ grep -B 1 mandarin

 

3. r자가 들어가 있는 과일을 출력하라.

[Test@localhost fileTest]$ grep r my

 

4. s자가 들어간 과일을 출력하되 라인번호도 출력하라.

[Test@localhost fileTest]$ grep s -n my

 

13.

find를 시간의 속성과 함께 사용할 수 있다.

ex) 최상위 루트에서 사이즈가 1000인 파일을 출력하자.

find / -size +1000 -print

ex2) 현재 디렉토리에서 크기가 1000이하인 파일을 출력하자.

find . -size -1000 -print

ex3) 10일 이전에 수정된 파일 검색

find . -mtime -10 -print

ex4) 10일 이내에 수정된 파일을 찾아 삭제하기

find -type f -mtime -10 -print

 

14.

man join

man sort

man wc - 파일의 크기 출력

man split

 

15.

cat > member

aaa 00-00

bbb 11-111

ccc 22-222

ddd 33-333

eee 44-444

 

[Test@localhost fileTest02] $ sort -o remember member

[Test@localhost fileTest02] $ cat remember

 

ex) member를 역순으로 출력해서 r01로 저장

[Test@localhost fileTest02]$ sort -r member -o r01

 

16.

wc, c, w, l, m

ex) member의 단어, 라인, 문자를 출력하자.

 

17.

man cut : 추출

man paste : 붙인다.

man split : 파일을 나눈다

 

ex) member 3-7의 문자를 추출하자.

cut -c 3-7 member

cut -c 3-7 member > T

 

18.

ex01) member에서 공백을 기준으로 문자를 추출하자.

cut -f1, 1 -d " " member

 

ex02) member에서 두 번째 필드에 -를 기준으로 문자를 추출한다.

cut -f2 -d " " member

 

ex03) 전화번호를 추출해서 phone 파일에 저장한다.

cut -f2 -d " " member > phone

 

ex04) aaa 00-00 을 aaa:00-00으로 만들어서 T1(aaa) T2(00-000)으로 만들어 T3에 저장한다.

cut -f1 -d " " member > pname (이름 분리)

paste -d ":" pname phone > T3

 

19.

ex01) 윈도우 공유 폴더에 book.csv를 넣자

ex02) [root@localhost sf_mydata] # mv 명령으로 /home/Test/fileTest02로 옮긴다

ex03) 위치를 /home/Test/fileTest02로 이동한다.

ex04) book.csv a1, c1을 추출해서 Hap에 저장한다.

 

20.

 

'국비교육' 카테고리의 다른 글

마지막 종강날  (0) 2019.06.27
Linux 6일차  (0) 2019.05.28
Virtual Box  (0) 2019.05.23
프로젝트  (0) 2019.05.22
Python 15일차  (0) 2019.05.21

댓글