๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’ป Extracurricular/๋ฉ‹์Ÿ์ด์‚ฌ์ž์ฒ˜๋Ÿผ11๊ธฐ

[1์ฃผ์ฐจ] Shell ๊ณผ์ œ

ex00

์ œ์ถœ ๋””๋ ‰ํ† ๋ฆฌ : ex00/

์ œ์ถœ ํŒŒ์ผ : lion

cat ๋ช…๋ น์–ด ์‹คํ–‰์„ ํ†ตํ•ด “Hello World!"๋ฅผ ๋ฐ˜ํ™˜ ํ›„ ๊ฐœํ–‰์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํŒŒ์ผ์„ ๋งŒ๋“œ์„ธ์š”. ํŒŒ์ผ์˜ ์ด๋ฆ„์€ lion ์ž…๋‹ˆ๋‹ค.

์˜ˆ์‹œ)

$ cat lion
Hello World!

 

๐Ÿ’ก ํ•„์š”ํ•œ ๋ฆฌ๋ˆ…์Šค(Linux) BASH ์‰˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฌธ๋ฒ•

โžก๏ธ ํด๋” ์ƒ์„ฑ

mkdir [ํด๋”๋ช…]

 

โžก๏ธ ํด๋” ๋“ค์–ด๊ฐ€๊ธฐ

cd [ํด๋”๋ช…]

 

โžก๏ธ ํŒŒ์ผ ์ƒ์„ฑ

cat > [ํŒŒ์ผ๋ช…]

 

โžก๏ธ ํŒŒ์ผ ์ถœ๋ ฅ

cat [ํŒŒ์ผ๋ช…]

 

 

ํ’€์ด๊ณผ์ •

 

1. ํด๋” ์ƒ์„ฑ ๋ฐ ํด๋” ๋“ค์–ด๊ฐ€๊ธฐ

mkdir ex00 #ex00 ํด๋” ์ƒ์„ฑ
cd ex00 #ex00 ํด๋” ๋“ค์–ด๊ฐ€๊ธฐ

 

 

 

 

2. ํŒŒ์ผ ์ƒ์„ฑ

cat > lion
Hello World!
^C

 

 

 

3. ๊ฒฐ๊ณผ

cat lion
# Hello World!

 


ex01

์ œ์ถœ ๋””๋ ‰ํ† ๋ฆฌ : ex01/

์ œ์ถœ ํŒŒ์ผ : env.sh

CUK1, CUK2 ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์ „์—ญ์œผ๋กœ ์ถ”๊ฐ€ํ•ด๋ด…์‹œ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ถœ๋ ฅ์ด ๋‚˜์˜ค๊ฒŒ ํ•˜์„ธ์š”.

์ถœ๋ ฅ)

$ ./env.sh
$CUK1 $CUK2
LIKE lion
$ echo $CUK1 $CUK2
LIKE lion

โš ๏ธ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์ง์ ‘ ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅํ•˜๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค.

 

๐Ÿ’ก ํ•„์š”ํ•œ ๋ฆฌ๋ˆ…์Šค(Linux) BASH ์‰˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฌธ๋ฒ•

โžก๏ธ์ „์—ญ๋ณ€์ˆ˜ ์ƒ์„ฑ

 

export ๋ณ€์ˆ˜๋ช…=๋‚ด์šฉ

 

โžก๏ธ ํ…์ŠคํŠธ ๋ฐ ๋ฌธ์ž์—ด ์ถœ๋ ฅ

 

echo [๋ณ€์ˆ˜๋ช… or ๋ฌธ์ž์—ด]

 

โžก๏ธ chmod ๊ถŒํ•œ ์„ค์ •

 

chmod +x [ํŒŒ์ผ๋ช…]

 

 

ํ’€์ด๊ณผ์ •

1. ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์ „์—ญ์œผ๋กœ ์ƒ์„ฑํ•˜๊ธฐ

export CUK1=LIKE
export CUK2=lion
echo $CUK1 $CUK2
# LIKE lion

 

2. ํŒŒ์ผ ์•ˆ์—์„œ ๋ณ€์ˆ˜ ์ถœ๋ ฅํ•˜๊ธฐ

echo "\$CUK1 \$CUK2"
echo $CUK1 $CUK2

 

 

3. ๊ฒฐ๊ณผ

./env.sh

 


ex02

์ œ์ถœ ๋””๋ ‰ํ† ๋ฆฌ : ex02/

์ œ์ถœ ํŒŒ์ผ : lion_to_catholic.sh

์œ„์—์„œ ์ถ”๊ฐ€ํ•œ ํ™˜๊ฒฝ๋ณ€์ˆ˜ CUK1, CUK2๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•ด์„œ Catholic ์„ ์ถœ๋ ฅํ•ด๋ด…์‹œ๋‹ค.

$ ./lion_to_catholic.sh
Catholic

โš ๏ธ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์ง์ ‘ ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅํ•˜๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค.

 

 

๐Ÿ’ก ํ•„์š”ํ•œ ๋ฆฌ๋ˆ…์Šค(Linux) BASH ์‰˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฌธ๋ฒ•

โžก๏ธ๋ฌธ์ž์—ด ์น˜ํ™˜ํ•˜๊ธฐ

echo [๋ฐ”๊พธ๊ณ  ์‹ถ์€ ๋ณ€์ˆ˜๋ช…] | tr [๊ธฐ์กด ๋ฌธ์ž์—ด] [๊ต์ฒดํ•  ๋ฌธ์ž์—ด]

 

 

ํ’€์ด๊ณผ์ •

1. ํŒŒ์ผ์ƒ์„ฑ

vi lion_to_catholic.sh

 

2. sh ํŒŒ์ผ

1) ํ™˜๊ฒฝ๋ณ€์ˆ˜ 'CUK1'์˜ 'LIKE' ๋ฌธ์ž์—ด์„ 'Cath'์œผ๋กœ ์น˜ํ™˜

2) ํ™˜๊ฒฝ๋ณ€์ˆ˜ 'CUK2'์˜ 'lion' ๋ฌธ์ž์—ด์„ 'olic'์œผ๋กœ ์น˜ํ™˜

echo $CUK1$CUK2 | tr LIKE Cath | tr lion olic

 

 

3. ๊ฒฐ๊ณผ


ex03

์ œ์ถœ ๋””๋ ‰ํ† ๋ฆฌ : ex03/

์ œ์ถœ ํŒŒ์ผ : how_many.sh

ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ์— ๋ช‡๊ฐœ์˜ ํŒŒ์ผ์ด ์žˆ๋Š”์ง€ ์ถœ๋ ฅํ•˜๋Š” ํŒŒ์ผ์„ ์ž‘์„ฑํ•˜์„ธ์š”

์˜ˆ์‹œ)

$ ./how_many.sh
12

 

๐Ÿ’ก ํ•„์š”ํ•œ ๋ฆฌ๋ˆ…์Šค(Linux) BASH ์‰˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฌธ๋ฒ•

โžก๏ธ ํ˜„์žฌ์œ„์น˜์—์„œ ํŒŒ์ผ ๊ฐœ์ˆ˜ ์„ธ๊ธฐ

ls -l | grep ^- | wc -l

 

 

ํ’€์ด๊ณผ์ •

1. ์‰˜ ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ ์ƒ์„ฑ

vi how_many.sh

 

2. how_many.sh ํŒŒ์ผ ์ž‘์„ฑ

1) ๋ณ€์ˆ˜ cnt์— ํ˜„์žฌ์œ„์น˜์˜ ํŒŒ์ผ ๊ฐœ์ˆ˜ ์ €์žฅ

cnt=($(ls -l | grep ^- | wc -l))
echo $cnt

 

 

 

3. ํŒŒ์ผ ๊ถŒํ•œ ๋ถ€์—ฌ

#chmod +x [ํŒŒ์ผ๋ช…]
chmod +x how_many.sh

 

4. ์‰˜ ์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰

#./[ํŒŒ์ผ๋ช…]
./how_many.sh

 

5. ๊ฒฐ๊ณผ

 

https://lee-mandu.tistory.com/420

 

๋ฆฌ๋ˆ…์Šค ํŒŒ์ผ ๊ฐœ์ˆ˜ ๋ฐ ๋””๋ ‰ํ† ๋ฆฌ(ํด๋”) ๊ฐœ์ˆ˜ ์„ธ๊ธฐ

๊ฐ„๋‹จํ•œ ๋ช…๋ น์–ด๋งŒ ์ ์–ด๋‘๊ธฐ ์œ„ํ•˜์—ฌ ํฌ์ŠคํŒ…ํ•ฉ๋‹ˆ๋‹ค. ํ˜„์žฌ ์œ„์น˜์—์„œ ๋””๋ ‰ํ† ๋ฆฌ ์ฆ‰ ํด๋” ๊ฐœ์ˆ˜ ์„ธ๊ธฐ ls -l | grep ^d | wc -l ์œ„์˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ ์‹œํ‚ค๋ฉด ํ˜„์žฌ ์œ„์น˜์˜ ๋””๋ ‰ํ† ๋ฆฌ(ํŒŒ์ผ) ๊ฐœ์ˆ˜๋ฅผ ์ฒดํฌ ํ•  ์ˆ˜ ์žˆ์Šต

lee-mandu.tistory.com


ex04

์ œ์ถœ ๋””๋ ‰ํ† ๋ฆฌ: ex04/

์ œ์ถœ ํŒŒ์ผ : test_touch.txt

touch ๋ช…๋ น์–ด๋Š”, ํŒŒ์ผ์˜ ์ƒ์„ฑ๊ณผ ํŒŒ์ผ์˜ ๋‚ ์งœ, ์‹œ๊ฐ„์„ ๋ณ€๊ฒฝํ•˜๋Š” ๋ช…๋ น์–ด ์ž…๋‹ˆ๋‹ค ์˜ต์…˜ ์—†์ด ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ์„œ๋ฒ„์˜ ํ˜„์žฌ ์‹œ๊ฐ„์œผ๋กœ ๋ณ€๊ฒฝ ๋ฉ๋‹ˆ๋‹ค.

$ touch [์˜ต์…˜] [ํŒŒ์ผ๋ช…]

ํ•ด๋‹น ๋ช…๋ น์–ด๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๊ฐ„๋‹จํ•œ txt ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ , ๋‚ด์šฉ์„ ์ž‘์„ฑํ•˜์—ฌ ์ถœ๋ ฅ ๋˜๊ฒŒ ํ•ด๋ด…์‹œ๋‹ค.

 

์˜ˆ์‹œ)

#ํŒŒ์ผ ์ƒ์„ฑ
$ touch test_touch.txt

#๋ฌธ๊ตฌ ์ถœ๋ ฅ
$ cat test_touch.txt
ํ…Œ์ŠคํŠธ ๋ฌธ๊ตฌ์ž…๋‹ˆ๋‹ค.

 

 

ํ’€์ด๊ณผ์ •

1. test_touch.txt ํŒŒ์ผ ์ƒ์„ฑ

touch test_touch.txt

 

 

2.  test_touch.txt ํŒŒ์ผ ์ˆ˜์ •

cat > test_touch.txt
์•„๊ธฐ์‚ฌ์ž ํฌ์•„์•™
^C

 

 

3. ๊ฒฐ๊ณผ

cat test_touch.txt
# ์•„๊ธฐ์‚ฌ์ž ํฌ์•„์•™

 


ex05

์ œ์ถœ ๋””๋ ‰ํ† ๋ฆฌ: ex05/

์ œ์ถœ ํŒŒ์ผ: test_cp.txt

cp๋Š” ์„œ๋ฒ„ ๊ธฐ๋ณธ ๋ช…๋ น์–ด์ค‘ ํ•˜๋‚˜์ด๋ฉฐ, ํŒŒ์ผ/ ๋””๋ ‰ํ† ๋ฆฌ ๋“ฑ ๋ณต์‚ฌ๊ธฐ๋Šฅ์„ ์ด์šฉํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ช…๋ น์–ด์ž…๋‹ˆ๋‹ค.

๋‹ค์–‘ํ•œ ์˜ต์…˜์„ ์ด์šฉํ•˜์—ฌ ๋ฎ์–ด์“ฐ๊ธฐ, ๋‹ค์ค‘ ๋ณต์‚ฌ ๋“ฑ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์•ž์„œ ์ œ์ž‘ํ•œ ํ…์ŠคํŠธ ํŒŒ์ผ์„ ๋ณต์‚ฌํ•ด๋ด…์‹œ๋‹ค.

์˜ˆ์‹œ)

$ cp test_touch.txt test_cp.txt

์‹คํ–‰๊ฒฐ๊ณผ)

$cat test_cp.txt
ํ…Œ์ŠคํŠธ ๋ฌธ๊ตฌ์ž…๋‹ˆ๋‹ค.

 

๐Ÿ’ก ํ•„์š”ํ•œ ๋ฆฌ๋ˆ…์Šค(Linux) BASH ์‰˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฌธ๋ฒ•

โžก๏ธ ํŒŒ์ผ ๋ณต์‚ฌํ•˜๊ธฐ

$ cp [์›๋ณธํŒŒ์ผ] [๋ณต์‚ฌํŒŒ์ผ]

 

 

ํ’€์ด๊ณผ์ •

1. ํŒŒ์ผ ๋ณต์‚ฌ

$ cp test_touch.txt test_cp.txt

 

2. ๊ฒฐ๊ณผ

cat test_cp.txt
# "test"
cat test_touch.txt
# "test"

 


ex06

์ œ์ถœ ๋””๋ ‰ํ† ๋ฆฌ: ex06/

์ œ์ถœ ํŒŒ์ผ: move_dir.sh

mv ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค๋ฅธ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ํŒŒ์ผ์„ ์˜ฎ๊ธฐ๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ด๋ด…์‹œ๋‹ค.

์‹คํ–‰๊ฒฐ๊ณผ) newdir ๋ผ๋Š” ๋””๋ ‰ํ† ๋ฆฌ๋กœ ํŒŒ์ผ์„ ์˜ฎ๊ธด ๊ฒฝ์šฐ (์˜ˆ)

~/newdir# ls
test.txt

 

 

๐Ÿ’ก ํ•„์š”ํ•œ ๋ฆฌ๋ˆ…์Šค(Linux) BASH ์‰˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฌธ๋ฒ•

โžก๏ธ mv ๋ช…๋ น์–ด : ํŒŒ์ผ ์˜ฎ๊ธฐ๊ธฐ 

mv [์ด๋™ํ•  ํŒŒ์ผ][์ด๋™๋  ์œ„์น˜]

 

ํ’€์ด๊ณผ์ •

1. ์ด๋™์‹œํ‚ฌ ํŒŒ์ผ ์ƒ์„ฑ

cat test.txt
# ์ด๋™์‹œํ‚ฌ ํŒŒ์ผ


2. ํ˜„์žฌ ์œ„์น˜์— ์žˆ๋Š” ํŒŒ์ผ ํ™•์ธ

ls
# move_dir.sh  newdir test.txt

 

3. ํ˜„์žฌ ํŒŒ์ผ ๊ฒฝ๋กœ ํ™•์ธํ•˜๊ธฐ

pwd
# /home/hyunjin/LikeLion-Common-Subject/ex06


4. move_dir.sh ํŒŒ์ผ ์ƒ์„ฑ

1) ๋‹ค๋ฅธ ํด๋”๋กœ ํŒŒ์ผ ์˜ฎ๊ธฐ๊ธฐ

/home/hyunjin/LikeLion-Common-Subject/ex06 ๊ฒฝ๋กœ์— ์žˆ๋Š” 'test.txt'๋ฅผ

/home/hyunjin/LikeLion-Common-Subject/ex06/newdir ๊ฒฝ๋กœ๋กœ ์˜ฎ๊น€

mv test.txt /home/hyunjin/LikeLion-Common-Subject/ex06/newdir

 

5. ๊ฒฐ๊ณผ


ex07

์ œ์ถœ ๋””๋ ‰ํ† ๋ฆฌ: ex07/

์ œ์ถœ ํŒŒ์ผ: find_file.sh

find ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ํ™•์žฅ์ž๊ฐ€ .sh ๋กœ ๋œ ํŒŒ์ผ์„ ์ฐพ๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ด๋ด…์‹œ๋‹ค.

์‹คํ–‰๊ฒฐ๊ณผ)

$ find_file.sh
/๊ฒฝ๋กœ/ํŒŒ์ผ์ด๋ฆ„.sh
/๊ฒฝ๋กœ/ํŒŒ์ผ์ด๋ฆ„2.sh

...

 

ํ’€์ด๊ณผ์ •

1. find_file.sh ํŒŒ์ผ ์ƒ์„ฑ

vi find_file.sh

 

2. find_file.sh ํŒŒ์ผ ์ˆ˜์ •

1) ์ด๋ฆ„์— ".sh"๊ฐ€ ๋“ค์–ด๊ฐ„ ํŒŒ์ผ ์ฐพ๊ธฐ

find . -name "*.sh"

 


3. ๊ฒฐ๊ณผ


ex08

์ œ์ถœ ๋””๋ ‰ํ† ๋ฆฌ: ex08/

์ œ์ถœ ํŒŒ์ผ: remove_file.sh

rm ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŒŒ์ผ์„ ์‚ญ์ œํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ด ๋ด…์‹œ๋‹ค.

 

๐Ÿ’ก ํ•„์š”ํ•œ ๋ฆฌ๋ˆ…์Šค(Linux) BASH ์‰˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฌธ๋ฒ•

โžก๏ธ rm ๋ช…๋ น์–ด : ํŒŒ์ผ ์‚ญ์ œ ๋ช…๋ น์–ด

rm [ํŒŒ์ผ๋ช…]

 

 

ํ’€์ด๊ณผ์ •

1. ์‚ญ์ œํ•  ํŒŒ์ผ ์ƒ์„ฑ

cat > file_.sh

 

2. remove_file.sh ํŒŒ์ผ ์ƒ์„ฑ

vi remove_file.sh
ls
# check_remove.sh  file_.sh  remove_file.sh

 

3. remove_file.sh ํŒŒ์ผ ์ˆ˜์ •

1) ํŒŒ์ผ์ด ์กด์žฌํ•˜๋Š”์ง€ ๊ฒ€์‚ฌํ•œ ํ›„ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ ํŒŒ์ผ์„ ์‚ญ์ œํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ ์ž‘์„ฑ

rm file_.sh

 

4. ๊ฒฐ๊ณผ

 

 

๐Ÿ’ฅ (์„ ํƒ์‚ฌํ•ญ) ํŒŒ์ผ์ด ์กด์žฌํ•˜๋Š”์ง€ ๊ฒ€์‚ฌํ•œ ํ›„, ์กด์žฌํ•  ๊ฒฝ์šฐ ํŒŒ์ผ์„ ์‚ญ์ œํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋„ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”!

๐Ÿ’ก ๋ฆฌ๋ˆ…์Šค ํŒŒ์ผ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•

test ๋ช…๋ น์–ด
test๋Š” ํŒŒ์ผ ๋ฐ ๋””๋ ‰ํ† ๋ฆฌ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๊ณ  true / false๋กœ ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ดํ•จ.

 

๋งŒ์•ฝ ์–ด๋–ค ํŒŒ์ผ์ด ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ "file exist"๋ผ๋Š” ๋ฌธ๊ตฌ๋ฅผ ์ถœ๋ ฅํ•˜๋ ค๋ฉด?
@ ํŒŒ์ผ์ด๋ฆ„ : './test_file.sh'

 

if test -f './test_file.sh'
then
  echo "file exist !!!";
fi

 

 

ํ’€์ด๊ณผ์ •

๋งŒ์•ฝ์— file_.sh ํŒŒ์ผ์ด ์žˆ๋‹ค๋ฉด?

'remove File'์„ ์ถœ๋ ฅํ•˜๊ณ  file_.sh๋ฅผ ์‚ญ์ œํ•ด๋ผ

๋งŒ์•ฝ์— file_.sh ํŒŒ์ผ์ด ์—†๋‹ค๋ฉด?

'already removed'๋ฅผ ์ถœ๋ ฅํ•ด๋ผ

 

if test -f './file_.sh'
then
        echo 'remove File';
        rm file_.sh;
else
        echo 'already removed'
fi

 

 


ex09

์ œ์ถœ ๋””๋ ‰ํ† ๋ฆฌ: ex09/

์ œ์ถœ ํŒŒ์ผ : myscript.sh

์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์ด ์กด์žฌํ•˜๋Š” ์ ˆ๋Œ€/์ƒ๋Œ€ ๊ฒฝ๋กœ๋ฅผ pwd๋ฅผ ์ด์šฉํ•˜์—ฌ ์–ป๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ด๋ด…์‹œ๋‹ค.

์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•  ๋•Œ, ๋ช…๋ น์–ด๋ฅผ ์ธ์ž๋กœ ๋ฐ›๋Š”๋ฐ์š”. ๊ทธ ์ธ์ž์˜ ๊ฒฝ๋กœ๋ฅผ ํ•ด์„ํ•ด์„œ ํŒŒ์ผ์˜ ์œ„์น˜๋ฅผ ๊ตฌํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

๐Ÿ’ก ํ„ฐ๋ฏธ๋„์—์„œ ๋ฐ›์€ ์ธ์ˆ˜ $0์„ dirnameํ•˜์—ฌ ๋””๋ ‰ํ† ๋ฆฌ ๋ช…์„ ์–ป๊ณ ,
      cd ๋ฅผ ํ†ตํ•ด ์ด๋™ํ•œ ๋””๋ ‰ํ† ๋ฆฌ(dirname์„ ํ†ตํ•ด ์–ป์€ ๋””๋ ‰ํ† ๋ฆฌ)์—์„œ ,
      pwd๋กœ ์ ˆ๋Œ€ ๊ฒฝ๋กœ ๊ฐ’์„ ๋ณ€์ˆ˜์— ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์„ ์ด์šฉํ•˜๋ฉด๋ฉ๋‹ˆ๋‹ค.

 

์‹คํ–‰ ๊ฒฐ๊ณผ )

 

$ bash myscript.sh
scriptName: myscript.sh
relative Path: .
Absolute Path: /mnt/d/home 

 

ํ‘œ์‹œ๋œ ๊ฒฝ๋กœ๋Š” ์˜ˆ์‹œ์ด๋ฏ€๋กœ ๋ณธ์ธ์˜ ๊ฒฝ๋กœ์— ๋งž๊ฒŒ ์ถœ๋ ฅ ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

 

๐Ÿ’ก ์‰˜์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์˜ ์ ˆ๋Œ€๊ฒฝ๋กœ ์–ป๊ธฐ

1) $0 : ๋ช…๋ น์–ด์˜ ์ฒซ๋ฒˆ์งธ ์ธ์ž

ex) sh ./myscript.sh abc๋ผ๋Š” ๋ช…๋ น์–ด๊ฐ€ ์žˆ๋‹ค๋ฉด?
$0์€ ./myscript.sh
$1์€ abc

 

2) dirname : ๋ฌธ์ž์—ด์—์„œ ๋””๋ ‰ํ† ๋ฆฌ๋งŒ ์ถ”์ถœํ•ด์ฃผ๋Š” ๋ช…๋ น์–ด

dirname ./myscript.sh์€ ./๋ฅผ ๋ฆฌํ„ด

 

โžก๏ธ ํŒŒ์ผ์˜ ์ƒ๋Œ€๊ฒฝ๋กœ๋ฅผ ์–ป๊ณ  ๊ทธ ์œ„์น˜๋กœ ์ด๋™ํ•œ ํ›„, pwd๋กœ ์ ˆ๋Œ€๊ฒฝ๋กœ๋ฅผ ์–ป์œผ๋ฉด ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์˜ ์ ˆ๋Œ€๊ฒฝ๋กœ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Œ.

 

 

ํ’€์ด๊ณผ์ •

1. myscript.sh ํŒŒ์ผ ์ƒ์„ฑ

vi myscript.sh

 

 

2. myscript.sh ํŒŒ์ผ ์ˆ˜์ •

relative=$(dirname ./myscript.sh)
absolute=$(cd $(dirname -- "${BASH_SOURCE[0]}") && pwd)

echo sriptName: $(basename $0)
echo relative Path: $relative
echo Absoulte PAth: $absolute

 

 

 

2. ๊ฒฐ๊ณผ

bash myscript.sh

 

 

https://codechacha.com/ko/how-to-get-path-of-bash-script/

 

Linux - Bash ์‰˜์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์˜ ์ ˆ๋Œ€๊ฒฝ๋กœ ์–ป๊ธฐ

์‰˜ ์Šคํฌ๋ฆฝํŠธ์˜ ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ์ฐพ๋Š” ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœํ•ฉ๋‹ˆ๋‹ค. ์ธ์ž๋กœ ๋ฐ›์€ ํŒŒ์ผ์˜ ๊ฒฝ๋กœ์™€ 'pwd -P', 'dirname' ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ํŒŒ์ผ์˜ ์ ˆ๋Œ€๊ฒฝ๋กœ๋ฅผ ๊ณ„์‚ฐํ•˜์˜€์Šต๋‹ˆ๋‹ค. source์™€ sh ๋ช…๋ น์–ด ๋ฐ ์‰˜์˜ ์‹คํ–‰ ์œ„์น˜์™€

codechacha.com


ex10

์ œ์ถœ ๋””๋ ‰ํ† ๋ฆฌ : ex10/

์ œ์ถœ ํŒŒ์ผ : create_dir.sh

mkdir์ปค๋งจ๋“œ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ํด๋”๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ด๋ด…์‹œ๋‹ค.

new_directory๋ผ๋Š” ์ƒˆ๋กœ์šด ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์ƒ์„ฑ์— ์„ฑ๊ณตํ•˜์˜€๋Š”์ง€ ๊ฒ€์‚ฌํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜์„ธ์š”.

mkdir ๋ช…๋ น์–ด ์‹คํ–‰ ํ›„, $?๋ฅผ ํ†ตํ•ด ๋ช…๋ น์–ด์˜ ์„ฑ๊ณต ์œ ๋ฌด๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

 

์กฐ๊ฑด)

์ข…๋ฃŒ ์ƒํƒœ๊ฐ€ 0์ผ ๊ฒฝ์šฐ, ์ฆ‰ ๋ช…๋ น์–ด๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์ˆ˜ํ–‰๋œ ๊ฒฝ์šฐ์—๋Š” "Directory created successfully." ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๊ณ ,

๊ทธ๋ ‡์ง€ ์•Š์€ ๊ฒฝ์šฐ์—๋Š” "Failed to create directory." ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

 

์‹คํ–‰๊ฒฐ๊ณผ)

$ bash create_dir.sh

Directory created successfully.

 

 

๐Ÿ’ก ํ•„์š”ํ•œ ๋ฆฌ๋ˆ…์Šค(Linux) BASH ์‰˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฌธ๋ฒ•

โžก๏ธ $?

bash ์‰˜์—์„œ ์ตœ๊ทผ ์‹คํ–‰ํ•œ ๋ช…๋ น์–ด์˜ ์ข…๋ฃŒ ์Šคํ…Œ์ดํ„ฐ์Šค๋ฅผ ๊ฐ€์ง„ ๋ณ€์ˆ˜์ตœ๊ทผ ์‹คํ–‰ํ•œ ํ•จ์ˆ˜์˜ return ๊ฐ’์„ ๊ฐ€์ง„ ๋ณ€์ˆ˜

→ ์ตœ๊ทผ ๋ช…๋ น์–ด์˜ ์ข…๋ฃŒ ์ƒํƒœ๊ฐ€ ์ •์ƒ(0)

→ ์ตœ๊ทผ ๋ช…๋ น์–ด์˜ ์ข…๋ฃŒ ์ƒํƒœ๊ฐ€ ๋น„์ •์ƒ(127)

 

 

ํ’€์ด๊ณผ์ •

1. create_dir.sh ํŒŒ์ผ ์ƒ์„ฑ

vi create_dir.sh

 

2. create_dir.sh ํŒŒ์ผ ์ˆ˜์ •

mkdir dir1
if [ $? -eq 0 ]
then
        echo "Directory created successfully"
else
        echo "Failed to create directory"
fi

 

3. ๊ฒฐ๊ณผ

hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/ex10$ vi create_dir.sh
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/ex10$ bash create_dir.sh
Directory created successfully
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/ex10$ ls
create_dir.sh  dir1
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/ex10$ bash create_dir.sh
mkdir: cannot create directory ‘dir1’: File exists
Failed to create directory

 

 

https://zetawiki.com/wiki/%EB%A6%AC%EB%88%85%EC%8A%A4_$%3F 

 

 

๋ฆฌ๋ˆ…์Šค $? - ์ œํƒ€์œ„ํ‚ค

๋‹ค์Œ ๋ฌธ์ž์—ด ํฌํ•จ...

zetawiki.com

https://blackinkgj.github.io/shell-program/

 

[Linux Shell] Linux ์‰˜(sh)์—์„œ์˜ if๋ฌธ ์‚ฌ์šฉ

Linux ์‰˜(sh)์—์„œ if๋ฌธ์„ ์‚ฌ์šฉ ํ•ด๋ณด๋„๋ก ํ•œ๋‹ค.

blackinkgj.github.io


 

Bonus00

์ œ์ถœ ๋””๋ ‰ํ† ๋ฆฌ : bonus00/

์ œ์ถœ ํŒŒ์ผ : ls.tar

๋‹ค์Œ๊ณผ ๊ฐ™์€ ํŒŒ์ผ ๋ฐ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ ls -l ๋ช…๋ น์„ ์‚ฌ์šฉํ•  ๋•Œ ์ถœ๋ ฅ์ด ๋‹ค์Œ ์ผ์น˜ํ•˜๋„๋ก ํ•„์š”ํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜์„ธ์š”

์ž‘์—…์ด ์™„๋ฃŒ๋˜๋ฉด tar -cf ls.tar * ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ ์ œ์ถœ ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

๊ฒฐ๊ณผ)

$ ls -l
total XX
drwx--xr-x 2 XX XX XX Jan 1 20:47 test0
-rwx--xr-- 1 XX XX 4 Jan 1 21:46 test1
dr-x---r-- 2 XX XX XX Jan 1 22:45 test2
-r-----r-- 2 XX XX 1 Jan 1 23:44 test3
-rw-r----x 1 XX XX 2 Jan 1 23:43 test4
-r-----r-- 2 XX XX 1 Jan 1 23:44 test5
lrwxrwxrwx 1 XX XX 5 Jan 1 22:20 test6 -> test0

 

๐Ÿ’ก ์˜ˆ์‹œ์—์„œ์˜ "XX"๋Š” ์‚ฌ๋žŒ๋งˆ๋‹ค ๋‹ค๋ฅด๊ฒŒ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค. ์‹ ๊ฒฝ์“ฐ์ง€ ๋งˆ์„ธ์š”.

๐Ÿ’ก ํƒ€์ž„์Šคํƒฌํ”„์— ์‹œ๊ฐ„ ๋Œ€์‹  ์˜ฌํ•ด ์—ฐ๋„๊ฐ€ ๋‚˜์™€๋„ ๊ดœ์ฐฎ์Šต๋‹ˆ๋‹ค.

โš ๏ธ ๋ฆฌ๋ˆ…์Šค ํŒŒ์ผ ๊ฒฝ๋กœ๊ฐ€ ์•„๋‹Œ ์œˆ๋„์šฐ ํŒŒ์ผ ๊ฒฝ๋กœ์ธ ๊ฒฝ์šฐ ๊ถŒํ•œ ์ˆ˜์ •์ด ์•ˆ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

๐Ÿ”ฅ RTFM!!!

 

 

๐Ÿ’ก ํ•„์š”ํ•œ ๋ฆฌ๋ˆ…์Šค(Linux) BASH ์‰˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฌธ๋ฒ•

โžก๏ธ chmod ๊ถŒํ•œ ์„ค์ •

ํŒŒ์ผ์—์„œ ํ•  ์ˆ˜ ์žˆ๋Š” ์ž‘์—…์€ ํฌ๊ฒŒ 3๊ฐ€์ง€

1. R : ํŒŒ์ผ์— ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ๊ธฐ (read)

2. W : ํŒŒ์ผ์— ๋ฐ์ดํ„ฐ๋ฅผ ์“ฐ๊ธฐ (write)

3. E : ํŒŒ์ผ ์‹คํ–‰ํ•˜๊ธฐ (execute)

 

๊ทธ๋ฆฌ๊ณ  ์ด ์„ธ ๊ฐ€์ง€ ๊ถŒํ•œ์„ ์•„๋ž˜ ์„ธ ๋ถ„์•ผ์˜ ์‚ฌ์šฉ์ž์—๊ฒŒ ๊ฐ๊ฐ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Œ

1. ํŒŒ์ผ์„ ์†Œ์œ ํ•œ ์‚ฌ์šฉ์ž(user)

2. ํŠน์ • ๊ทธ๋ฃน(group)์— ์†Œ์†๋œ ์‚ฌ์šฉ์ž

3. ๊ทธ ์™ธ ์‚ฌ์šฉ์ž(others)

 

user group others
r w e r w e r w e
4 2 1 4 2 1 4 2 1

 

๋งŒ์•ฝ drwx--xr-x ์„ ํ‘œํ˜„ํ•˜๋ ค๋ฉด?

1. d - directory : ํด๋”๋ผ๋Š” ๋œป
2. ๊ถŒํ•œ ์„ค์ • rwx rwx rwx์—์„œ rwx --x r-x๋งŒ ํ—ˆ์šฉ๋˜์—ˆ๋‹ค๋Š” ๋œป
    1) user์˜ ๊ฒฝ์šฐ : rwx ๋ชจ๋‘ ํ—ˆ์šฉ๋˜์—ˆ์Œ โžก๏ธ 4 + 2 + 1 = 7
    2) group์˜ ๊ฒฝ์šฐ : x ๋งŒ ํ—ˆ์šฉ๋˜์—ˆ์Œ โžก๏ธ 0 + 0 + 1 = 1
    1) others์˜ ๊ฒฝ์šฐ : r, x ๋งŒ ํ—ˆ์šฉ๋˜์—ˆ์Œ โžก๏ธ 4 + 0 + 1 = 5
3. ๊ฒฐ๋ก 
    1) ํด๋”๋ฅผ ์ƒ์„ฑํ•œ ํ›„
    2) ํด๋”์˜ ๊ถŒํ•œ์„ 715๋กœ ์ฃผ๋ฉด ๋จ.
mkdir test0
chmod 715 test0
ls -l
# total 4
# drwx--xr-x 2 hyunjin hyunjin 4096 Mar 19 16:23 test0

https://recipes4dev.tistory.com/175

 

๋ฆฌ๋ˆ…์Šค chmod ๋ช…๋ น์–ด ์‚ฌ์šฉ๋ฒ•. (Linux chmod command) - ๋ฆฌ๋ˆ…์Šค ํŒŒ์ผ ๊ถŒํ•œ ๋ณ€๊ฒฝ.

1. ๋ฆฌ๋ˆ…์Šค ํŒŒ์ผ ์‚ฌ์šฉ ๊ถŒํ•œ ๋ฆฌ๋ˆ…์Šค์—์„œ, ํŒŒ์ผ(File)์„ ์‚ฌ์šฉํ•ด ํ•  ์ˆ˜ ์žˆ๋Š” ์ž‘์—…์€ ํฌ๊ฒŒ ์„ธ ๊ฐ€์ง€๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํŒŒ์ผ์— ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ๊ธฐ. (r = read). ํŒŒ์ผ์— ๋ฐ์ดํ„ฐ๋ฅผ ์“ฐ๊ธฐ. (w = write). ํŒŒ์ผ ์‹ค

recipes4dev.tistory.com

 

 

ํ’€์ด๊ณผ์ •

1. test0

hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ mkdir test0
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ chmod 715 test0
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ ls -l
total 4
drwx--xr-x 2 hyunjin hyunjin 4096 Mar 19 16:23 test0

 

2. test1

hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ cat > test1
^C
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ chmod 714 test1
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ ls -l
total 4
drwx--xr-x 2 hyunjin hyunjin 4096 Mar 19 16:23 test0
-rwx--xr-- 1 hyunjin hyunjin    0 Mar 19 16:24 test1

 

3. test2

hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ mkdir test2
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ chmod 504 test2
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ ls -l
total 8
drwx--xr-x 2 hyunjin hyunjin 4096 Mar 19 16:23 test0
-rwx--xr-- 1 hyunjin hyunjin    0 Mar 19 16:24 test1
dr-x---r-- 2 hyunjin hyunjin 4096 Mar 19 16:25 test2

 

3. test3

hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ cat > test3
^C
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ chmod 404 test3
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ ls -l
total 8
drwx--xr-x 2 hyunjin hyunjin 4096 Mar 19 16:23 test0
-rwx--xr-- 1 hyunjin hyunjin    0 Mar 19 16:24 test1
dr-x---r-- 2 hyunjin hyunjin 4096 Mar 19 16:25 test2
-r-----r-- 1 hyunjin hyunjin    0 Mar 19 16:25 test3

 

4. test4

hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ cat > test4
^C
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ chmod 641 test4
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ ls -l
total 8
drwx--xr-x 2 hyunjin hyunjin 4096 Mar 19 16:23 test0
-rwx--xr-- 1 hyunjin hyunjin    0 Mar 19 16:24 test1
dr-x---r-- 2 hyunjin hyunjin 4096 Mar 19 16:25 test2
-r-----r-- 1 hyunjin hyunjin    0 Mar 19 16:25 test3
-rw-r----x 1 hyunjin hyunjin    0 Mar 19 16:28 test4

 

5. test5

๐Ÿ’กํ•˜๋“œ ๋งํฌ ํŒŒ์ผ ์ƒ์„ฑ

ln "์›๋ณธ ํŒŒ์ผ๋ช…" "ํ•˜๋“œ ๋งํฌ ํŒŒ์ผ๋ช…"

 

hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ ln test3 test5
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ ls -l
total 8
drwx--xr-x 2 hyunjin hyunjin 4096 Mar 19 16:23 test0
-rwx--xr-- 1 hyunjin hyunjin    0 Mar 19 16:24 test1
dr-x---r-- 2 hyunjin hyunjin 4096 Mar 19 16:25 test2
-r-----r-- 2 hyunjin hyunjin    0 Mar 19 16:25 test3
-rw-r----x 1 hyunjin hyunjin    0 Mar 19 16:28 test4
-r-----r-- 2 hyunjin hyunjin    0 Mar 19 16:25 test5

 

6. test6

๐Ÿ’ก์‹ฌ๋ณผ๋ฆญ ๋งํฌ ํŒŒ์ผ ์ƒ์„ฑ

ln -s "์›๋ณธ ํŒŒ์ผ๋ช…" "์‹ฌ๋ณผ๋ฆญ ๋งํฌ ํŒŒ์ผ๋ช…"

 

hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ ln -s test0 test6
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ ls -l
total 8
drwx--xr-x 2 hyunjin hyunjin 4096 Mar 19 16:23 test0
-rwx--xr-- 1 hyunjin hyunjin    0 Mar 19 16:24 test1
dr-x---r-- 2 hyunjin hyunjin 4096 Mar 19 16:25 test2
-r-----r-- 2 hyunjin hyunjin    0 Mar 19 16:25 test3
-rw-r----x 1 hyunjin hyunjin    0 Mar 19 16:28 test4
-r-----r-- 2 hyunjin hyunjin    0 Mar 19 16:25 test5
lrwxrwxrwx 1 hyunjin hyunjin    5 Mar 19 16:50 test6 -> test0

 

7. ํŒŒ์ผ ํฌ๊ธฐ ๋งž์ถ”๊ธฐ

๐Ÿ’ก๋ฆฌ๋ˆ…์Šค ํŒŒ์ผ ํฌ๊ธฐ ์„ค์ •ํ•˜๊ธฐ

fallocate -l "ํŒŒ์ผํฌ๊ธฐ" "ํŒŒ์ผ๋ช…"

 

hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ fallocate -l 4 test1
#ํฌ๊ธฐ ์ˆ˜์ •์„ ์œ„ํ•ด test3์˜ ๊ถŒํ•œ์„ ๋ชจ๋‘ ํ—ˆ์šฉ์œผ๋กœ ๋ณ€๊ฒฝ
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ chmod 777 test3
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ fallocate -l 1 test3
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ fallocate -l 2 test4
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ fallocate -l 1 test5
#ํฌ๊ธฐ ์ˆ˜์ •์„ ์™„๋ฃŒํ–ˆ์œผ๋ฏ€๋กœ test3์˜ ๊ถŒํ•œ ์žฌ์„ค์ •
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ chmod 404 test3
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ ls -l
total 24
drwx--xr-x 2 hyunjin hyunjin 4096 Mar 19 16:23 test0
-rwx--xr-- 1 hyunjin hyunjin    4 Mar 19 17:00 test1
dr-x---r-- 2 hyunjin hyunjin 4096 Mar 19 16:25 test2
-r-----r-- 2 hyunjin hyunjin    1 Mar 19 17:02 test3
-rw-r----x 1 hyunjin hyunjin    2 Mar 19 17:01 test4
-r-----r-- 2 hyunjin hyunjin    1 Mar 19 17:02 test5
lrwxrwxrwx 1 hyunjin hyunjin    5 Mar 19 16:50 test6 -> test0

 

8. ๊ฒฐ๊ณผ

hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ tar -cf ls.tar *
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ ls
ls.tar  test0  test1  test2  test3  test4  test5  test6
hyunjin@DESKTOP-1RAUJUA:~/LikeLion-Common-Subject/bonus00$ ls -l
total 36
-rw-r--r-- 1 hyunjin hyunjin 10240 Mar 19 17:02 ls.tar
drwx--xr-x 2 hyunjin hyunjin  4096 Mar 19 16:23 test0
-rwx--xr-- 1 hyunjin hyunjin     4 Mar 19 17:00 test1
dr-x---r-- 2 hyunjin hyunjin  4096 Mar 19 16:25 test2
-r-----r-- 2 hyunjin hyunjin     1 Mar 19 17:02 test3
-rw-r----x 1 hyunjin hyunjin     2 Mar 19 17:01 test4
-r-----r-- 2 hyunjin hyunjin     1 Mar 19 17:02 test5
lrwxrwxrwx 1 hyunjin hyunjin     5 Mar 19 16:50 test6 -> test0

 

 

https://m.blog.naver.com/dufwjdrkdgur/221489384249

 

linux - ln ๋ช…๋ น์–ด(๋งํฌ ํŒŒ์ผ ์ƒ์„ฑ) ํ•˜๋“œ๋งํฌ,์‹ฌ๋ณผ๋ฆญ๋งํฌ,inode๊ฐœ๋…

ln ๋ช…๋ น์–ด๋Š” Link์˜ ์ค„์ž„๋ง๋กœ ๋ฆฌ๋ˆ…์Šค์—์„œ ๋งํฌํŒŒ์ผ์„ ๋งŒ๋“œ๋Š” ๋ช…๋ น์–ด์ด๋‹ค. ๋งํฌํŒŒ์ผ์—๋Š” 2๊ฐ€์ง€ ์ข…๋ฅ˜๊ฐ€ ์žˆ๋‹ค...

blog.naver.com

https://info-lab.tistory.com/302

 

[Linux] ๋ฆฌ๋ˆ…์Šค์—์„œ ํŠน์ • ํฌ๊ธฐ์˜ ํŒŒ์ผ์„ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•

ํŒŒ์ผ ์—…๋กœ๋“œ ๊ธฐ๋Šฅ์„ ๊ฐœ๋ฐœํ•˜๋Š” ๋„์ค‘ ํŒŒ์ผ ์—…๋กœ๋“œ ํฌ๊ธฐ(Size) ์ œํ•œ ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ ํ…Œ์ŠคํŠธ๊ฐ€ ํ•„์š”ํ•˜์˜€๋‹ค. ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด์„œ๋Š” ๋‹ค์–‘ํ•œ ํฌ๊ธฐ๋ฅผ ๊ฐ€์ง„ ํŒŒ์ผ๋“ค์ด ํ•„์š”ํ•˜์˜€์œผ๋ฉฐ, ๊ฐœ๋ฐœ ์žฅ๋น„์— ์—ฌ๋Ÿฌ ๋‹ค์–‘ํ•œ

info-lab.tistory.com