반응형
Notice
Recent Posts
Recent Comments
Link
Today
Total
07-05 05:44
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Archives
관리 메뉴

iOS 개발 기록 블로그

linux command : diff, find, tar, in (link), sed, cp, mv 명령어 뿌시기 2탄 본문

Linux

linux command : diff, find, tar, in (link), sed, cp, mv 명령어 뿌시기 2탄

crazydeer 2021. 11. 26. 22:24
반응형

18. diff 명령어

" 파일 간의 차이점을 찾아서 알려주는 명령어 "

 

)

[orcl:~]$ diff emp.txt emp7.txt
14a15
>       7839 KING       PRESIDENT          0 17-NOV-81           5000         0           10

 

 

예제 1) 아래와 같이 개의 파일 이름을 각각 물어보게 하고 결과로 파일의 내용의 차이가 출력되게 하시오

 

보기)

$ sh diff.sh


비교할 첫번째 파일명을 입력하세요: emp.txt


비교할 두번째 파일명을 입력하세요: emp7.txt


14a15
>       7839 KING       PRESIDENT          0 17-NOV-81           5000         0           10

 

)

#1/bin/bash


echo "  "
echo -n "비교할 첫번째 파일명를 입력하세요: "
read file1
echo "   "
echo -n "비교할 두번째 파일명을 입력하세요: "
read file2
echo "    "
diff $file1 $file2

 

 

 

19. find 명령어

" 검색하고 싶은 파일을 찾을 사용하는 명령어 "

 

)

$ find 디렉토리 -name 파일명 -print


[orcl:~]$ find ~ -name emp.txt -print
/home/oracle/emp.txt

 

 

예제 2-1) /home/oracle 밑에 test100 test200이라는 디렉토리를 생성하고 밑에 emp.txt 각각 복사하시오

 

)

[orcl:~]$ mkdir test100 test200


[orcl:~]$ cp emp.txt ./test100/emp.txt
[orcl:~]$ cp emp.txt ./test200/emp.txt

 

 

 

예제 2-2) /home/oracle 밑에 있는 emp.txt 검색하시오

 

1)

[orcl:~]$ find ~ -name emp.txt -print
/home/oracle/test100/emp.txt
/home/oracle/test200/emp.txt
/home/oracle/emp.txt

 

2)

[orcl:~]$ find . -maxdepth 1 -name 'emp.txt'
./emp.txt
[orcl:~]$ find . -maxdepth 2 -name 'emp.txt'
./test100/emp.txt
./test200/emp.txt
./emp.txt

 

 

 

예제 3) 파일을 검색하는 스크립트를 아래와 같이 생성하시오

 

보기)

$ sh find_file.sh


현재 디렉토리 밑에 검색할 파일명을 입력하세요: emp.txt


depth 값: 2

 

결과)

./test100/emp.txt
./test200/emp.txt
./emp.txt

 

)

#1/bin/bash


echo "  "
echo -n "현재 디렉토리 밑에 검색할 파일명을 입력하세요: "
read file1
echo "   "
echo -n "depth 값: "
read depth
echo "    "
find . -maxdepth $depth -name $file1

 

 

 

20. tar 명령어

" 파일을 압축하거나 압축 해제하는 명령어 "

 

)

1. 압축할
$ tar cvf 압축파일명 압축파일대상


2. 압축 해제할
$ tar xvf 압축파일명 압축해제할 위치

 

옵션)

-c  compress 여러 개의 파일을 하나로 만들어라
-v  view, 압축되는 과정을 보여달라
-f  file, 생성되는 파일명을 지정
-x  extract, 묶여있는 파일을 풀어줘라
-C  압축 풀릴 위치를 지정

 

 

예제 4) /home/oracle 밑에 test63 이라는 디렉토리를 만들고 밑에 emp.txt 복사해서 아래의

파일들을 생성하시오

 

보기)

a.txt b.txt c.txt d.txt e.txt

 

)

[orcl:~]$ mkdir test63
[orcl:~]$ cp emp.txt ./test63/a.txt
[orcl:~]$ cp emp.txt ./test63/b.txt
[orcl:~]$ cp emp.txt ./test63/c.txt
[orcl:~]$ cp emp.txt ./test63/d.txt
[orcl:~]$ cp emp.txt ./test63/e.txt

 

 

 

예제 5) test63 디렉토리 밑에 있는 확장자 .txt 파일들을 all.tar라는 이름으로 압축하시오

 

)

[orcl:~]$ tar cvf all.tar ./test63/*.txt

 

결과)

[orcl:~]$ ls -l
total 29408
drwxr-xr-x  6 oracle oinstall     4096 Oct 13  2012 Adobe
drwx------  2 oracle oinstall     4096 Nov 13  2012 Desktop
drwxr-xr-x 15 oracle oinstall     4096 Jun 21 16:51 R-3.2.3
-rw-r--r--  1 oracle oinstall 29816176 Dec 10  2015 R-3.2.3.tar.gz
-rw-r--r--  1 oracle oinstall        0 Jun 22 11:36 a.txt
-rw-r--r--  1 oracle oinstall    10240 Jun 25 14:25 all.tar

 

 

 

예제 6) /home/oracle 밑에 test65라는 디렉토리를 생성하고 밑에 all.tar 압축파일의 압축을 해제하시오

 

)

[orcl:~]$ mkdir test65
[orcl:~]$ tar xvf all.tar -C /home/oracle/test65

 

 

 

21. ln (link) 명령어

윈도우의 바로가기 기능과 유사함

" 내가 자주 열어봐야 하는 파일이 있다면 바로가기를 생성해 놓아 편하게 열어볼 있는 기능 "

 

)

$ ln -s "링크 파일위치와 파일명" "바로가기 이름"

 

[orcl:~]$ ln -s /u01/app/oracle/product/11.2.0/dbhome_1/sqlplus/admin/glogin.sql glogin.sql
[orcl:~]$ ls

 

 

[orcl:~]$ vi glofin.sql

 

[orcl:~]$ vi glogin.sql
[orcl:~]$ sqlplus scott/tiger

 

 

SQL> select ename, sal from emp where empno = 7788;
SQL> ed

 

 

 

22. .bash_profile 설정하는 방법

oracle 유저를 위한 리눅스 환경설정 파일

 

)

[orcl:~]$ vi .bash_profile

 

 

[orcl:~]$ su - oracle
Password:
여기는 운영서버입니다. 조심히 작업하세요~

 

 

예제 7) oracle 유저로 접속할 때마다 아래의 메시지가 출력되게 하시오

 

보기)

저한테 그러시는 건데요 ㅡㅡ

 

)

[orcl:~]$ vi .bash_profile
[orcl:~]$ su - oracle
Password:
여기는 운영서버입니다. 조심히 작업하세요~
저한테 왜 그러시는 건데요 ㅡㅡ

 

설명)

su - oracle : 오라클로 접속하는 명령어

 

 

 

23. sed 명령어

" grep 명령어는 파일의 특정 내용을 검색하는 기능을 갖는다면
sed 명령어는 검색 뿐만 아니라 내용을 변경할 수도 있다 "

 

)

$ sed 's/KING/yyy/' emp.txt


emp.txt 출력할 KING yyy 변경해서 출력한다
KING yyy 스위치하겠다
실제로는 바뀌지 않고 출력되는 화면에서만 바뀐

 

 

예제 8) 위의 변경된 내용대로 출력한 내용을 emp9.txt 저장하시오

 

)

[orcl:~]$ sed 's/KING/yyy/' emp.txt >> emp9.txt

 

 

 

24. cp 명령어

" 파일을 복사하는 명령어 "

 

)

$ cp 위치/원본 파일명 위치/복사할 파일명


백업할 쓰는 중요한 기능

 

 

예제 9) 리눅스의 oracle 계정을 위한 환경설정파일인 .bash_profile 백업하시오

 

)

[orcl:~]$ cp .bash_profile .bash_profile_backup
[orcl:~]$ ls -a

 

 

 

예제 10) /home/oracle 밑에 있는 확장자 .txt 파일들 전부를 /home/oracle/backup 이라는 디렉토리에

복사하시오

 

)

$ mkdir backup
$ cp /home/oracle/*.txt /home/oracle/backup/

 

 

 

25. mv 명령어

" 파일의 이름을 바꾸거나 파일을 다른 디렉토리로 이동하는 명령어 "   move

 

)

$ mv [기존 파일명] [새로운 파일명 또는 파일 위치]
[orcl:~]$ mv emp400.txt emp500.txt
[orcl:~]$ mv emp.txt ./backup/

 

 

예제 11) /home/oracle/backup 밑에 있는 emp.txt 지금 현재 디렉토리인 /home/oracle 밑으로

이동시키시오

 

)

[orcl:~]$ cd backup
[orcl:backup]$ mv emp.txt ~
[orcl:backup]$ cd ..
[orcl:~]$ ls

 

 

반응형