Linux system

Shell Script : ํŒŒ์ผ ํ˜•์‹ ํ™•์ธ ๋ฐ ๋ณต์‚ฌ

NENGIN 2024. 3. 21. 12:34

์Šคํฌ๋ฆฝํŠธ

#!/bin/bash

echo -n "ํŒŒ์ผ๋ช…์„ ์ž…๋ ฅํ•˜์„ธ์š” : ";read name


if [ -e $name ];then
        if [ -f $name ];then
                echo "$nameํŒŒ์ผ์€ ์ผ๋ฐ˜ํŒŒ์ผ์ž…๋‹ˆ๋‹ค."
                cp $name /root/blog
        elif [ -d $name ];then
                echo "$nameํŒŒ์ผ์€ ๋””๋ ‰ํ„ฐ๋ฆฌํŒŒ์ผ์ž…๋‹ˆ๋‹ค."
        elif [ -L $name ];then
                echo "$nameํŒŒ์ผ์€ ๋งํฌํŒŒ์ผ์ž…๋‹ˆ๋‹ค."
                cp $name /root/blog
        else
                echo "ํ•ด๋‹น ํŒŒ์ผ์€ ๋””๋ ‰ํ„ฐ๋ฆฌ/๋งํฌ/์ผ๋ฐ˜ํŒŒ์ผ์— ํ•ด๋‹นํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."
        fi
else
        echo "ํ•ด๋‹นํŒŒ์ผ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."
fi

 

ํŒŒ์ผ ์‹คํ–‰ ๊ฒฐ๊ณผ

[root@localhost ~]# sh bloging.sh 
ํŒŒ์ผ๋ช…์„ ์ž…๋ ฅํ•˜์„ธ์š” : file2
file2ํŒŒ์ผ์€ ์ผ๋ฐ˜ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.

// ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ ๋ณต์‚ฌ๋œ ํŒŒ์ผ ํ™•์ธ
[root@localhost ~]# ls /root/blog
file2

[root@localhost ~]# sh bloging.sh 
ํŒŒ์ผ๋ช…์„ ์ž…๋ ฅํ•˜์„ธ์š” : blog
blogํŒŒ์ผ์€ ๋””๋ ‰ํ„ฐ๋ฆฌํŒŒ์ผ์ž…๋‹ˆ๋‹ค.