DAY75. Linux ํ์ผ ๊ด๋ จ ๋ช ๋ น์ด
๋ฆฌ๋ ์ค ํ์ผ์ ์ข ๋ฅ์ ํน์ง
1. ์ผ๋ฐํ์ผ : ๋ฐ์ดํฐ ์ ์ฅ ๋ชฉ์
2. ๋๋ ํฐ๋ฆฌ : ๋ฆฌ๋ ์ค์์๋ ํ์ผ๋ก ์ทจ๊ธ
3. ์ฌ๋ฒ๋ฆญ ๋งํฌ : ์๋ณธํ์ผ์ ๋์ ํด์ ๋ค๋ฅธ ์ด๋ฆ์ผ๋ก ํ์ผ๋ช ์ง์ ex) ์๋์ฐ ๋ฐ๋ก๊ฐ๊ธฐ ์์ด์ฝ
4. ์ฅ์น ํ์ผ : ํ๋๋์คํฌ,ํค๋ณด๋ ๊ฐ์ ๊ฐ์ข ์ฅ์น๋ ํ์ผ ์ทจ๊ธ
ํ์ผ ๋ด์ฉ ์ถ๋ ฅํ๊ธฐ
์๋ก์ด ํ์ผ ์์ฑ(cat)
ํ์) cat > ์์ฑํ ํ์ผ๋ช
ํ์ผ ๋ด์ฉ ์์ฑ ๊ธฐ๋ฅ ์ ๊ณต
hadoop@localhost ~]$ cat > exam2.txt
this is exam2.txt file
file end
[hadoop@localhost ~]$ ls
download exam2.txt test1 ๋ค์ด๋ก๋ ์ฌ์ง -> exam2 ํ์ผ ์์ฑ ํ์ธ
exam mysql-connector-java-8.0.27 text1 ๋ฌธ์ ์์
exam. mysql-connector-java-8.0.27.tar.gz z ๋ฐํํ๋ฉด ์์
exam.txt test.tar ๊ณต๊ฐ ๋น๋์ค
* ์ข ๋ฃ ๋จ์ถํค : Ctrl + D
ํ์ผ ๋ด์ฉ์ ๋ค๋ฅธ ํ์ผ๋ก ์ด๋
ํ์) cat [์๋ณธํ์ผ๋ช ] > [๋ชฉ์ ์ง ํ์ผ๋ช ]
์๋ณธํ์ผ์ ๋ด์ฉ์ ๋ชฉ์ ์ง ํ์ผ๋ก ์ด๋
๋ชฉ์ ์ง ํ์ผ์ด ์์ผ๋ฉด ์๋ก ๋ง๋ค์ด์ง๋ค
[hadoop@localhost ~]$ cat exam2.txt > exam3.txt
[hadoop@localhost ~]$ cat exam3.txt
this is exam2.txt file
file end
๊ธฐ์กด ํ์ผ ๋ด์ฉ์ ์ถ๊ฐ
ํ์) cat [๋ด์ฉ์ถ๊ฐํ ํ์ผ๋ช ] >> [๊ธฐ์กด ํ์ผ๋ช ]
๊ธฐ์กด ํ์ผ์ ๋ค๋ฅธ ํ์ผ์ ๋ด์ฉ ์ถ๊ฐ
[hadoop@localhost ~]$ cat exam.txt >> exam3.txt
[hadoop@localhost ~]$ cat exam3.txt -> exam3.txt ํ์ผ์ exam.txt๋ด์ฉ ์ถ๊ฐ
this is exam2.txt file
file end
์ฐ๋ฆฌ๋๋ผ ๋๋๋ฏผ๊ตญ
๋๋ ํ๊ธธ๋์
๋๋ค.
ํ๋ฉด ๋จ์ ํ์ผ ๋ด์ฉ ์ถ๋ ฅ
ํ์) more [์ต์ ] ํ์ผ๋ช
* ์ต์ +ํ ๋ฒํธ : ์ถ๋ ฅ์ ์์ํ ํ๋ฒํธ
๋ด์ฉ์ด ๋ง์ ๊ฒฝ์ฐ ํ ํ๋ฉด๋จ์ ์ถ๋ ฅ
[hadoop@localhost ~]$ more /etc/services
# /etc/services:
# $Id: services,v 1.55 2013/04/14 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2013-04-10
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports
# are included, only the more common ones.
#
# The latest IANA port assignments can be gotten from
# http://www.iana.org/assignments/port-numbers
# The Well Known Ports are those from 0 through 1023.
# The Registered Ports are those from 1024 through 49151
# The Dynamic and/or Private Ports are those from 49152 through 65535
#
# Each line describes one service, and is of the form:
#
# service-name port/protocol [aliases ...] [# comment]
tcpmux 1/tcp # TCP port service multiplexer
tcpmux 1/udp # TCP port service multiplexer
rje 5/tcp # Remote Job Entry
rje 5/udp # Remote Job Entry
echo 7/tcp
echo 7/udp
discard 9/tcp sink null
discard 9/udp sink null
systat 11/tcp users
systat 11/udp users
daytime 13/tcp
daytime 13/udp
qotd 17/tcp quote
qotd 17/udp quote
msp 18/tcp # message send protocol (historic)
msp 18/udp # message send protocol (historic)
chargen 19/tcp ttytst source
chargen 19/udp ttytst source
ftp-data 20/tcp
ftp-data 20/udp
# 21 is registered to ftp, but also used by fsp
ftp 21/tcp
* Ctrl + Z : ๊ฐ์ ์ข ๋ฃ
more
more ๋ช ๋ น์ด ํ spacebar๋ฅผ ๋๋ฅด๋ฉด ๋ค์ ํ๋ฉด์ด ์ถ๋ ฅ, enterํค๋ฅผ ๋๋ฅด๋ฉด ํ ์ค์ฉ ์คํฌ๋กค
* q : more ๋ช ๋ น์ด ์ข ๋ฃ
tail
tail [์ต์ ] ํ์ผ๋ช
ํ์ผ์ ๋ท๋ถ๋ถ ๋ช ํ์ ์ถ๋ ฅ
+ํ ๋ฒํธ : ์ง์ ํ ํ๋ถํฐ ๋๊น์ง ์ถ๋ ฅ
- ์ซ์ : ํ๋ฉด์ ์ถ๋ ฅํ ํ์ ์๋ฅผ ์ง์ (๊ธฐ๋ณธ ๊ฐ : 10)
- f : ํ์ผ ์ถ๋ ฅ์ด ์ข ๋ฃ๋์ง ์๊ณ ์ฃผ๊ธฐ์ ์ผ๋ก ๊ณ์ ์ถ๋ ฅ
[hadoop@localhost ~]$ tail -10 /etc/services -> 10ํ๋ถํฐ ์ถ๋ ฅ
3gpp-cbsp 48049/tcp # 3GPP Cell Broadcast Service Protocol
isnetserv 48128/tcp # Image Systems Network Services
isnetserv 48128/udp # Image Systems Network Services
blp5 48129/tcp # Bloomberg locator
blp5 48129/udp # Bloomberg locator
com-bardac-dw 48556/tcp # com-bardac-dw
com-bardac-dw 48556/udp # com-bardac-dw
iqobject 48619/tcp # iqobject
iqobject 48619/udp # iqobject
matahari 49000/tcp # Matahari Broker
ํ์ผ ๋ณต์ฌํ๊ธฐ(cp)
๊ธฐ๋ฅ : ํ์ผ์ด๋ ๋๋ ํฐ๋ฆฌ๋ฅผ ๋ณต์ฌํ๋ค.
ํ์) cp [์ต์ ] ํ์ผ๋ช 1/๋๋ ํฐ๋ฆฌ๋ช 1 ํ์ผ๋ช 2/๋๋ ํฐ๋ฆฌ๋ช 2
์ต์
- i : ๋์ผ ํ์ผ ์กด์ฌํ๋ฉด ๋ฎ์ด์ฐ๊ธฐ ์ฌ๋ถ ๋ฌผ์.
- r :๋๋ ํฐ๋ฆฌ๋ฅผ ๋ณต์ฌํ ๋ ์ง์
ex)
cp file1 file2
cp file1 file2 file3 dir1
cp –r dir1 dir2
cp ๋ช ๋ น์ด์ ์ต์
์ต์ | ์ต์ ๋ด์ฉ |
-a | ํ์ผ์ ์์ฑ,๋งํฌ ์ ๋ณด๋ค์ ๊ทธ๋๋ก ์ ์งํ๋ฉด์ ๋ณต์ฌํ๋ค. |
-b | ์ด๋ฏธ ํ์ผ์ด ์กด์ฌํ๋ฉฐ ๋ฐฑ์ ๋ณธ์ ๋ง๋ค๊ณ ๋ณต์ฌํ๋ค |
-f | ๊ธฐ์กด์ ํ์ผ์ ๊ฐ์ ๋ก ์ญ์ ํ๊ณ ๋ณต์ฌํ๋ค |
-i | ๋ฎ์ด์ฐ๊ธฐ ์ ์ ์ฌ๋ถ๋ฅผ ๋ฌป๋๋ค |
-p | ์๋ณธ ํ์ผ์ ์์ ์ฃผ,๊ทธ๋ฃน,๊ถํ,์๊ฐ์ ๋ณด๋ฅผ ๋ณต์ฌํ๋ค |
-r,-R | ๋๋ ํฐ๋ฆฌ๋ฅผ ๋ณต์ฌํ๋ค |
๊ฐ์ ๋๋ ํฐ๋ฆฌ ์์์ ๋ค๋ฅธ ํ์ผ๋ช ๋ณต์ฌ
- ๋์ผํ ํ์ผ์ด ์กด์ฌํ๋ฉด ์๋ฌ ๋ฐ์
[hadoop@localhost ~]$ cat > sample
this is sample file
file end
[hadoop@localhost ~]$ cp sample sample1 ->ํ์ผ ๋ณต์ฌ
[hadoop@localhost ~]$ ls
download exam. exam2.txt mysql-connector-java-8.0.27 sample test.tar text1 ๊ณต๊ฐ ๋ฌธ์ ๋น๋์ค ์์
exam exam.txt exam3.txt mysql-connector-java-8.0.27.tar.gz sample1 test1 z ๋ค์ด๋ก๋ ๋ฐํํ๋ฉด ์ฌ์ง ์์
[hadoop@localhost ~]$ cat sample1
this is sample file
file end
๋ค๋ฅธ ๋๋ ํฐ๋ฆฌ์ ๋ณต์ฌํ๊ณ ๋ด์ฉ์ ํ์ธ(cat)
- ํ์ผ์ ๊ทผ๊ถํ ๋์ผ
[hadoop@localhost ~]$ cp exam3.txt ./test1
[hadoop@localhost ~]$ ls -l ./test1 -> ๋ค๋ฅธ ๋๋ ํฐ๋ฆฌ์ ํ์ผ ๋ณต์ฌ
-rw-rw-r--. 1 hadoop hadoop 84 1์ 6 20:17 ./test1
[hadoop@localhost ~]$ ls -l exam3.txt -> ์ ๊ทผ ๊ถํ ํ์ธ
-rw-rw-r--. 1 hadoop hadoop 84 1์ 6 20:11 exam3.txt
๋๋ ํฐ๋ฆฌ๋ฅผ ๋ณต์ฌํ ๊ฒฝ์ฐ์๋ ์ต์ –r
ex) cp –r ./test1 ./test1_cp
[hadoop@localhost ~]$ ls ./test1
./test1
[hadoop@localhost ~]$ cp -r ./test1 ./test1_cp
[hadoop@localhost ~]$ ls -l -> test1_cp๋๋ ํฐ๋ฆฌ ๋ณต์ฌ
ํฉ๊ณ 4216
drwxrwxr-x. 2 hadoop hadoop 4096 12์ 27 11:02 download
-rw-rw-r--. 1 hadoop hadoop 0 12์ 24 10:59 exam
-rw-rw-r--. 1 hadoop hadoop 0 12์ 24 10:51 exam.
-rw-rw-r--. 1 hadoop hadoop 53 12์ 24 11:00 exam.txt
-rw-rw-r--. 1 hadoop hadoop 31 1์ 6 20:07 exam2.txt
-rw-rw-r--. 1 hadoop hadoop 84 1์ 6 20:11 exam3.txt
drwxr-xr-x. 3 hadoop hadoop 4096 9์ 29 03:17 mysql-connector-java-8.0.27
-rw-rw-r--. 1 hadoop hadoop 4216166 12์ 27 10:50 mysql-connector-java-8.0.27.tar.gz
-rw-rw-r--. 1 hadoop hadoop 29 1์ 6 20:15 sample
-rw-rw-r--. 1 hadoop hadoop 29 1์ 6 20:15 sample1
-rw-rw-r--. 1 hadoop hadoop 10240 12์ 27 10:10 test.tar
-rw-rw-r--. 1 hadoop hadoop 84 1์ 6 20:17 test1
-rw-rw-r--. 1 hadoop hadoop 84 1์ 6 20:18 test1_cp -> test1_cp ๋๋ ํฐ๋ฆฌ ๋ณต์ฌ ํ์ธ
ํ์ผ ์ญ์ ํ๊ธฐ (rm)
ํ์ : rm [์ต์ ] ํ์ผ๋ช /๋๋ ํฐ๋ฆฌ๋ช
๊ธฐ๋ฅ : ํ์ผ์ ์ญ์ ํ๋ค
์ต์
- i : ์ง์ ํ ํ์ผ์ ์ญ์ ํ ์ฌ๋ถ๋ฅผ ๋ฌป๋๋ค.
- r: ์ง์ ํ ๋๋ ํฐ๋ฆฌ๋ฅผ ์ญ์ ํ๋ค. ์ฌ์ฉ์) rm file rm –r dir
rm ๋ช ๋ น์ ์ต์
์ต์ | ์ต์ ๋ด์ฉ |
-i | ํ์ผ์ ์ญ์ ํ๊ธฐ ์ ์ญ์ ์ฌ๋ถ๋ฅผ ํ์ธํ๋ค |
-f | ๊ฐ์ ๋ก ์ญ์ ํ๋ค. |
-r | ๋๋ ํฐ๋ฆฌ์ผ ๊ฒฝ์ฐ ๊ฒฝ๋ก์ ํ์ผ์ ํจ๊ป ์ญ์ ํ๋ค. |
-v | ํ์ผ ์ง์ฐ๋ ์ ๋ณด๋ฅผ ์์ธํ๊ฒ ๋ณด์ฌ์ค๋ค. |
rm –rf
๋ค์ํ์ผ์ด ์กด์ฌํ๋ ๋๋ ํฐ๋ฆฌ ํ๊บผ๋ฒ์ ์ญ์
[hadoop@localhost ~]$ ls -l test1_cp
-rw-rw-r--. 1 hadoop hadoop 84 1์ 6 20:18 test1_cp
[hadoop@localhost ~]$ rm -rf test1_cp
[hadoop@localhost ~]$ ls -l test1_cp -> ํ์ผ๊ณผ ๋๋ ํฐ๋ฆฌ ์ญ์
ls: cannot access test1_cp: ๊ทธ๋ฐ ํ์ผ์ด๋ ๋๋ ํฐ๋ฆฌ๊ฐ ์์ต๋๋ค
ํ์ผ ์ด๋ ๋ช ๋ น์ด(mv)
ํ์ : mv [์ต์ ] ์๋ณธํ์ผ๋ช 1/๋๋ ํฐ๋ฆฌ๋ช 1 ๋ณ๊ฒฝํ์ผ๋ช 2/๋ณ๊ฒฝ๋๋ ํฐ๋ฆฌ๋ช 2
๊ธฐ๋ฅ : ํ์ผ์ ์ด๋ํ๋ค
์ต์
- i : ํ์ผ๋ช 2/๋๋ ํฐ๋ฆฌ2๊ฐ ์กด์ฌํ๋ฉด ๋ฎ์ด์ฐ๊ธฐ ์ ๋ฌด๋ฅผ ๋ฌป๋๋ค.
- f: ๊ฐ์ ๋ก ์ด๋์ํจ๋ค ์ฌ์ฉ์) mv ์๋ณธfile1 ๋ณ๊ฒฝfile2
mv๋ช ๋ น์ด
[hadoop@localhost ~]$ mv exam.txt example.txt -> ํ์ฌ์ ๋๋ ํฐ๋ฆฌ์์ ํ์ผ ์ด๋ฆ ๋ณ๊ฒฝ
[hadoop@localhost ~]$ ls
download exam. exam3.txt mysql-connector-java-8.0.27 sample test.tar text1 ๊ณต๊ฐ ๋ฌธ์ ๋น๋์ค ์์
exam exam2.txt example.txt mysql-connector-java-8.0.27.tar.gz sample1 test1 z ๋ค์ด๋ก๋ ๋ฐํํ๋ฉด ์ฌ์ง ์์
[hadoop@localhost ~]$ mv example.txt ./test1 -> ํ์ฌ์ ํ์ผ์ ๋ค๋ฅธ ๋๋ ํฐ๋ฆฌ๋ก ์ด๋
[hadoop@localhost ~]$ ls -l ./test1
-rw-rw-r--. 1 hadoop hadoop 53 12์ 24 11:00 ./test1
ํ์ผ ๋งํฌ(1)
์ฌ์ฉ๋ชฉ์ : ๊ธฐ์กด ํ์ผ์ ์๋ก์ด ํ์ผ๋ช ์ฐ๊ฒฐ
๋ค๋ฅธ ํ์ผ์ ๋ํ๋ด๋ ๊ฐ์ํ์ผ
๋งค์ฐ ์ ์ ๊ณต๊ฐ์ ์ฐจ์งํ๋ค.
๋ณต์กํ ๋๋ ํฐ๋ฆฌ ๊ณ์ธต๊ตฌ์กฐ๋ฅผ ํฌํจํ์ฌ ํ์ผ๋ช ์ด ๋ณต์กํ ๊ฒฝ์ฐ ๊ฐ๋จํ ์ด๋ฆ์ผ๋ก ์ฐ๊ฒฐ ๋ ์ ์ฉํ๋ค.
์ข ๋ฅ
- ํ๋ ๋งํฌ : ๊ธฐ์กดํ์ผ์ ๋ํ ๋ณต์ฌ๋ณธ (๋์ผํ inode, ๋ฐ์ดํฐ, ์์ ๊ถ, ํ๊ฐ๊ถ)
- ์ฌ๋ณผ๋ฆญ ๋งํฌ : ๋ค๋ฅธ ํ์ผ์ ๋ํ ํฌ์ธํฐ๊ฐ ์๋ ์์ ํ์ผ (์๋์ฐ์ ๋ฐ๋ก๊ฐ๊ธฐ ์์ด์ฝ๊ณผ ์ ์ฌ)
Inode(index node) ๊ตฌ์กฐ
ํ๋๋งํฌ(ln) ๋ช ๋ น์ด
๋์ผํ ํ์ผ์์คํ ๋ด์ ํํฐ์ ์์ ๋์ผํ inode์ ๋ณด๋ฅผ ๊ฐ์ง๋ ํ์ผ
ํ์ : ln [์ต์ ] ์๋ณธํ์ผ๋ช ๋งํฌํ์ผ๋ช
๊ธฐ๋ฅ : ํ์ผ์ ๋งํฌ๋ฅผ ์์ฑ
์ต์ s :์ฌ๋ณผ๋ฆญ ๋งํฌํ์ผ ์์ฑ (Inode๋ฒํธ๊ฐ ์๋ณธํ์ผ๊ณผ ๋์ผ)
ex) ln test lntest -> ํ๋ ๋งํฌ
ln –s test lntest -> ์ฌ๋ณผ๋ฆญ ๋งํฌ
์ฌ๋ณผ๋ฆญ ๋งํฌ ๋ช ๋ น์ด
์๋ณธํ์ผ์ ์ด๋ฆ๋ง ๋งํฌํ๋ ๋ฐฉ์. Inode๋ฒํธ๊ฐ ์๋ณธํ์ผ๊ณผ ๋ค๋ฅด๋ค.
์๋ณธํ์ผ์ด ์ญ์ ๋๋ฉด ์๋ฏธ ์๋ ํ์ผ์ด ๋๋ค. (์๋ณธํ์ผ๊ณผ ์ฌ๋ณผ๋ฆญ ๋งํฌ ํ์ผ์ ๋ณ๊ฐ)
ํ์ผ์ข ๋ฅ๊ฐ l(L)๋ก ํ์
ํ์ผ ์ด๋ฆ ๋ค์ ์๋ณธ ํ์ผ ์ด๋ฆ ํ์(-> data1)
ํ์ : ln -s ์๋ณธํ์ผ๋ช ์ฌ๋ณผ๋ฆญ๋งํฌํ์ผ๋ช
ํ์ผ ๊ฒ์(์ฐพ๊ธฐ)
1) grep ๋ช ๋ น์ด
๊ธฐ๋ฅ : ํ์ผ ๋ด์ ์ง์ ํ ํจํด์ ํฌํจํ๋ ํ ์ฐพ๊ธฐ
ํ์ : grep [์ต์ ] ํจํด [ํ์ผ๋ช ]
์ต์
- i : ๋๋ฌธ์,์๋ฌธ์๋ฅผ ๋ชจ๋ ๊ฒ์
- l : ํด๋น ํจํด์ ํฌํจํ๋ ํ์ผ์ด๋ฆ์ ์ถ๋ ฅ
- n: ํ๋ฒํธ ์ถ๋ ฅ
[hadoop@localhost ~]$ vi /etc/passwd
root:x:0:0:root:/root:/bin/bash -> passwd ํ์ผ์ root ๋จ์ด๊ฐ ํฌํจ๋ ํ
operator:x:11:0:operator:/root:/sbin/nologin
[hadoop@localhost ~]$ grep root /etc/passwd -> Grep๋ช
๋ น์ด๋ก passwd ํ์ผ์ 'root'๊ฐ ํฌํจ๋ ํ ๊ฒ์
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[hadoop@localhost ~]$ cat > grep.txt
Hong 1234 ํ๊ธธ๋ 35
Lee 1234 ์ด์์ 45
yoo 4567 ์ ๊ด์ 25
[hadoop@localhost ~]$ grep -b Hong grep.txt -> ๊ฒ์๋ ๋ผ์ธ์์ ๋ธ๋ก ๋ฒํธ์ ํจ๊ป ์ถ๋ ฅ
0:Hong 1234 ํ๊ธธ๋ 35
[hadoop@localhost ~]$ grep -c 1234 grep.txt -> ๋งค์นญ๋ ๋ผ์ธ ๊ฐ์๋ง ์ถ๋ ฅ
2
[hadoop@localhost ~]$ grep -i Yoo grep.txt -> ๋์๋ฌธ์๋ฅผ ๊ตฌ๋ถํ์ง ์๊ณ ๊ฒ์ํ์ฌ ์ถ๋ ฅ
yoo 4567 ์ ๊ด์ 25
[hadoop@localhost ~]$ grep -i hong grep.txt
Hong 1234 ํ๊ธธ๋ 35
[hadoop@localhost ~]$ grep -v ์ ๊ด์ grep.txt -> ํจํด๊ณผ ๋งค์นญ๋์ง ์๋ ๋ผ์ธ๋ง ์ถ๋ ฅ
Hong 1234 ํ๊ธธ๋ 35
Lee 1234 ์ด์์ 45
2) find ๋ช ๋ น์ด
๊ธฐ๋ฅ : ํ์ผ์ด๋ฆ, ํฌ๊ธฐ, ์์ ์, ์ข ๋ฅ ๋ฑ์ผ๋ก ํ์ผ ๊ฒ์
ํ์ : find ๊ฒฝ๋ก [์ต์ ] [ํ์ผ๋ช ]
์ต์
- name : ์ด๋ฆ์ผ๋ก ๊ฒ์
- size : ํฌ๊ธฐ๋ก ๊ฒ์
- user : ์์ ์๋ก ๊ฒ์
- type : ์ข ๋ฅ๋ก ๊ฒ์
Type ์ต์ ๊ฐ
d : directory
f : regular file
b : block device file
c : character device file
n : network special file
p : named pipe s : socket