728x90

ln
 개요
 링크파일을 만드는 명령어
 심볼릭 링크와 하드 링크의 개념을 알고 사용해야 한다.

 심볼릭 링크
 윈도우즈의 '바로가기'라고 생각하면 된다.
 원본파일을 가리키고만 있으므로 원본파일과는 무관하다.
 즉 심볼릭 링크 파일을 지우더라도 원본파일은 지워지지 않는다.

 하드 링크
 원본파일과 다른 이름으로 존재하는 동일한 파일이며 원본파일과 동일한 내용의 다른 파일이라고 볼 수 있다.
 따라서 하드 링크 파일을 지우더라도 원본파일을 지워지지 않는다.
 하지만 원본파일의 내용이 바뀔경우에는 링크파일의 내용도 바뀌게 된다.

 Options
 -s : 심볼릭 링크 생성

 ex) ln [-option] [원본파일] [대상파일]
     "test"라는 파일에 대한 하드링크 파일 "abc"를 생성하라 

$ ln test abc


     "tmp"라는 디렉토리에 대한 심볼릭 링크 "/var/abc"를 생성하라

$ ln -s /tmp /var/abc

lrwxr-xr-x   1 i48   if              5 Oct 30 19:15 /var/abc -> /tmp
728x90

'IT > OS (Unix Linux Windows)' 카테고리의 다른 글

[java 관련 명령어] jinfo / jstat / jstack / jmap  (0) 2018.11.06
[명령어]basename / dirname  (0) 2018.11.02
[명령어]split  (0) 2018.10.30
[명령어]find  (0) 2018.10.30
[명령어]touch  (0) 2018.10.30
728x90

split
 개요
 큰 파일을 여러 작은 파일로 나눌때 사용.

 Options
 -a : 분할되는 파일뒤에 붙는 접두어의 길이
 -b : 분할되는 기준을 바이트로 분할 (라인 중간에 내용이 잘릴 수 있음)
  -C : 분할되는 기준을 바이트로 분할 (라인 기준 내용을 잘리지 않음)
 -d : 분할되는 파일뒤에 붙는 접두어가 영문이 아닌 숫자로 지정
 -l : 분할되는 기준을 라인수로 분할

 ex)split [-option] [값] [대상파일]
     50MB 단위로 test.txt 파일을 짤라라.

$ split -b 50m test.txt


     test라는 파일을 "test_"로 시작되는 파일로 짤라라.

$ split test test_
$ ll
total 4916
-rw-r--r--   1 in8   if        1254527 Oct 30 17:10 test
-rw-r--r--   1 in8   if          79782 Oct 30 17:10 test_aa
-rw-r--r--   1 in8   if          87920 Oct 30 17:10 test_ab
-rw-r--r--   1 in8   if          79254 Oct 30 17:10 test_ac
-rw-r--r--   1 in8   if          94671 Oct 30 17:10 test_ad
-rw-r--r--   1 in8   if          94174 Oct 30 17:10 test_ae
-rw-r--r--   1 in8   if          90584 Oct 30 17:10 test_af
-rw-r--r--   1 in8   if          82640 Oct 30 17:10 test_ag
-rw-r--r--   1 in8   if          89124 Oct 30 17:10 test_ah
-rw-r--r--   1 in8   if          76908 Oct 30 17:10 test_ai
-rw-r--r--   1 in8   if          77784 Oct 30 17:10 test_aj
-rw-r--r--   1 in8   if          83850 Oct 30 17:10 test_ak
-rw-r--r--   1 in8   if          81390 Oct 30 17:10 test_al
-rw-r--r--   1 in8   if          86587 Oct 30 17:10 test_am
-rw-r--r--   1 in8   if          89396 Oct 30 17:10 test_an
-rw-r--r--   1 in8   if          60463 Oct 30 17:10 test_ao


     test라는 파일을 "test_"로 시작되면서 접두어가 4글자가 들어가는 파일로 짤라라.

$ split -a 4 test test_
$ ll
total 4916
-rw-r--r--   1 i8   if        1254527 Oct 30 17:10 test
-rw-r--r--   1 i8   if          79782 Oct 30 17:11 test_aaaa
-rw-r--r--   1 i8   if          87920 Oct 30 17:11 test_aaab
-rw-r--r--   1 i8   if          79254 Oct 30 17:11 test_aaac
-rw-r--r--   1 i8   if          94671 Oct 30 17:11 test_aaad
-rw-r--r--   1 i8   if          94174 Oct 30 17:11 test_aaae
-rw-r--r--   1 i8   if          90584 Oct 30 17:11 test_aaaf
-rw-r--r--   1 i8   if          82640 Oct 30 17:11 test_aaag
-rw-r--r--   1 i8   if          89124 Oct 30 17:11 test_aaah
-rw-r--r--   1 i8   if          76908 Oct 30 17:11 test_aaai
-rw-r--r--   1 i8   if          77784 Oct 30 17:11 test_aaaj
-rw-r--r--   1 i8   if          83850 Oct 30 17:11 test_aaak
-rw-r--r--   1 i8   if          81390 Oct 30 17:11 test_aaal
-rw-r--r--   1 i8   if          86587 Oct 30 17:11 test_aaam
-rw-r--r--   1 i8   if          89396 Oct 30 17:11 test_aaan
-rw-r--r--   1 i8   if          60463 Oct 30 17:11 test_aaao


     test라는 파일을 50000byte 단위 및 "test_"로 시작되는 파일로 짤라라.

$ split -b 50000 test test_
$ ll
total 3276
-rw-r--r-- 1 i8 if 1622959 Oct 30 17:16 test
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_aa
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ab
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ac
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ad
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ae
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_af
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ag
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ah
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ai
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_aj
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ak
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_al
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_am
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_an
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ao
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ap
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_aq
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ar
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_as
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_at
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_au
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_av
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_aw
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ax
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ay
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_az
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_ba
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_bb
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_bc
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_bd
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_be
-rw-r--r-- 1 i8 if   50000 Oct 30 17:20 test_bf
-rw-r--r-- 1 i8 if   22959 Oct 30 17:20 test_bg

$ tail test_aa
 * [002] section: 0.000 sec, accumulation: 0.000 sec [<Leave> befEute]
 * [003] section: 0.000 sec, accumulation: 0.000 sec [<Enter> exe]
[Sertrol@142][2018-10-17 01:55:00] JOB BEGIN
Serviator load Start
----


아래의 -C 옵션과 비교 해보았을때 마지막 라인이 완전한 문장이 아닌 잘려나간 문장임을 확인 할 수 있음.

$ split -C 50000 test test_
$ ll
total 3276
-rw-r--r-- 1 in8 if 1622959 Oct 30 17:16 test
-rw-r--r-- 1 in8 if   49996 Oct 30 17:21 test_aa
-rw-r--r-- 1 in8 if   49986 Oct 30 17:21 test_ab
-rw-r--r-- 1 in8 if   49977 Oct 30 17:21 test_ac
-rw-r--r-- 1 in8 if   49980 Oct 30 17:21 test_ad
-rw-r--r-- 1 in8 if   49973 Oct 30 17:21 test_ae
-rw-r--r-- 1 in8 if   49978 Oct 30 17:21 test_af
-rw-r--r-- 1 in8 if   49993 Oct 30 17:21 test_ag
-rw-r--r-- 1 in8 if   49977 Oct 30 17:21 test_ah
-rw-r--r-- 1 in8 if   49990 Oct 30 17:21 test_ai
-rw-r--r-- 1 in8 if   49975 Oct 30 17:21 test_aj
-rw-r--r-- 1 in8 if   49939 Oct 30 17:21 test_ak
-rw-r--r-- 1 in8 if   49986 Oct 30 17:21 test_al
-rw-r--r-- 1 in8 if   49999 Oct 30 17:21 test_am
-rw-r--r-- 1 in8 if   49925 Oct 30 17:21 test_an
-rw-r--r-- 1 in8 if   49984 Oct 30 17:21 test_ao
-rw-r--r-- 1 in8 if   49982 Oct 30 17:21 test_ap
-rw-r--r-- 1 in8 if   49956 Oct 30 17:21 test_aq
-rw-r--r-- 1 in8 if   49985 Oct 30 17:21 test_ar
-rw-r--r-- 1 in8 if   49965 Oct 30 17:21 test_as
-rw-r--r-- 1 in8 if   49980 Oct 30 17:21 test_at
-rw-r--r-- 1 in8 if   49805 Oct 30 17:21 test_au
-rw-r--r-- 1 in8 if   49820 Oct 30 17:21 test_av
-rw-r--r-- 1 in8 if   49985 Oct 30 17:21 test_aw
-rw-r--r-- 1 in8 if   49957 Oct 30 17:21 test_ax
-rw-r--r-- 1 in8 if   49984 Oct 30 17:21 test_ay
-rw-r--r-- 1 in8 if   49965 Oct 30 17:21 test_az
-rw-r--r-- 1 in8 if   49985 Oct 30 17:21 test_ba
-rw-r--r-- 1 in8 if   49998 Oct 30 17:21 test_bb
-rw-r--r-- 1 in8 if   49902 Oct 30 17:21 test_bc
-rw-r--r-- 1 in8 if   49839 Oct 30 17:21 test_bd
-rw-r--r-- 1 in8 if   49949 Oct 30 17:21 test_be
-rw-r--r-- 1 in8 if   49951 Oct 30 17:21 test_bf
-rw-r--r-- 1 in8 if   24293 Oct 30 17:21 test_bg

$ tail test_aa
 * [002] section: 0.000 sec, accumulation: 0.000 sec [<Leave> befEute]
 * [003] section: 0.000 sec, accumulation: 0.000 sec [<Enter> exe]
[Sertrol@142][2018-10-17 01:55:00] JOB BEGIN
Serviator load Start


     test라는 파일을 접두어가 숫자로 들어가면서 test_"로 시작되는 파일로 짤라라.

$ split -d test test_     
$ ll
total 3220
-rw-r--r-- 1 in8 if 1622959 Oct 30 17:16 test
-rw-r--r-- 1 in8 if   49052 Oct 30 17:22 test_00
-rw-r--r-- 1 in8 if   49275 Oct 30 17:22 test_01
-rw-r--r-- 1 in8 if   49281 Oct 30 17:22 test_02
-rw-r--r-- 1 in8 if   49148 Oct 30 17:22 test_03
-rw-r--r-- 1 in8 if   49109 Oct 30 17:22 test_04
-rw-r--r-- 1 in8 if   63140 Oct 30 17:22 test_05
-rw-r--r-- 1 in8 if   56321 Oct 30 17:22 test_06
-rw-r--r-- 1 in8 if   69088 Oct 30 17:22 test_07
-rw-r--r-- 1 in8 if   66838 Oct 30 17:22 test_08
-rw-r--r-- 1 in8 if   69371 Oct 30 17:22 test_09
-rw-r--r-- 1 in8 if   68597 Oct 30 17:22 test_10
-rw-r--r-- 1 in8 if   72990 Oct 30 17:22 test_11
-rw-r--r-- 1 in8 if   68579 Oct 30 17:22 test_12
-rw-r--r-- 1 in8 if   75471 Oct 30 17:22 test_13
-rw-r--r-- 1 in8 if   75097 Oct 30 17:22 test_14
-rw-r--r-- 1 in8 if   78746 Oct 30 17:22 test_15
-rw-r--r-- 1 in8 if   72071 Oct 30 17:22 test_16
-rw-r--r-- 1 in8 if   75266 Oct 30 17:22 test_17
-rw-r--r-- 1 in8 if   70921 Oct 30 17:22 test_18
-rw-r--r-- 1 in8 if   72679 Oct 30 17:22 test_19
-rw-r--r-- 1 in8 if   66426 Oct 30 17:22 test_20
-rw-r--r-- 1 in8 if   66381 Oct 30 17:22 test_21
-rw-r--r-- 1 in8 if   59174 Oct 30 17:22 test_22
-rw-r--r-- 1 in8 if   58722 Oct 30 17:22 test_23
-rw-r--r-- 1 in8 if   49021 Oct 30 17:22 test_24
-rw-r--r-- 1 in8 if   22195 Oct 30 17:22 test_25


     test라는 파일을 10000라인을 기준 및 test_"로 시작되는 파일로 짤라라.

$ split -l 10000 test test_
$ ll
total 3220
-rw-r--r-- 1 in8 if 1622959 Oct 30 17:16 test
-rw-r--r-- 1 in8 if   49052 Oct 30 17:22 test_00
-rw-r--r-- 1 in8 if   49275 Oct 30 17:22 test_01
-rw-r--r-- 1 in8 if   49281 Oct 30 17:22 test_02
-rw-r--r-- 1 in8 if   49148 Oct 30 17:22 test_03
-rw-r--r-- 1 in8 if   49109 Oct 30 17:22 test_04
-rw-r--r-- 1 in8 if   63140 Oct 30 17:22 test_05
-rw-r--r-- 1 in8 if   56321 Oct 30 17:22 test_06
-rw-r--r-- 1 in8 if   69088 Oct 30 17:22 test_07
-rw-r--r-- 1 in8 if   66838 Oct 30 17:22 test_08
-rw-r--r-- 1 in8 if   69371 Oct 30 17:22 test_09
-rw-r--r-- 1 in8 if   68597 Oct 30 17:22 test_10
-rw-r--r-- 1 in8 if   72990 Oct 30 17:22 test_11
-rw-r--r-- 1 in8 if   68579 Oct 30 17:22 test_12
-rw-r--r-- 1 in8 if   75471 Oct 30 17:22 test_13
-rw-r--r-- 1 in8 if   75097 Oct 30 17:22 test_14
-rw-r--r-- 1 in8 if   78746 Oct 30 17:22 test_15
-rw-r--r-- 1 in8 if   72071 Oct 30 17:22 test_16
-rw-r--r-- 1 in8 if   75266 Oct 30 17:22 test_17
-rw-r--r-- 1 in8 if   70921 Oct 30 17:22 test_18
-rw-r--r-- 1 in8 if   72679 Oct 30 17:22 test_19
-rw-r--r-- 1 in8 if   66426 Oct 30 17:22 test_20
-rw-r--r-- 1 in8 if   66381 Oct 30 17:22 test_21
-rw-r--r-- 1 in8 if   59174 Oct 30 17:22 test_22
-rw-r--r-- 1 in8 if   58722 Oct 30 17:22 test_23
-rw-r--r-- 1 in8 if   49021 Oct 30 17:22 test_24
-rw-r--r-- 1 in8 if   22195 Oct 30 17:22 test_25

$ wc -l test*
  25448 test
  10000 test_aa
  10000 test_ab
   5448 test_ac
728x90

'IT > OS (Unix Linux Windows)' 카테고리의 다른 글

[명령어]basename / dirname  (0) 2018.11.02
[명령어]ln  (0) 2018.10.30
[명령어]find  (0) 2018.10.30
[명령어]touch  (0) 2018.10.30
[명령어]파일시스템 관련 df / du  (0) 2018.10.30
728x90

find
개요
특정 파일의 위치를 검색

Options
-name : 이름
-user : 소유자
-perm : 퍼미션
-szie : 크기
-mtime : 수정시간(modified)
-type : 파일타입

type 옵션 아규먼트
b : 블록특수파일
c : 문자특수파일
d : 디렉토리
f : 일반파일
l : 심볼릭링크
p : 파이프파일
s : 소켓
ex)  파일타입이 일반파일인  파일을 찾아라

$ find . -type f


size 옵션 아큐먼트
b : 블록단위
c : byte
k : kbyte
w : 2byte word
ex) 일반파일의 크기가 256byte인 파일을 찾아라

$ find . -type f -size 256c


일반파일의 크기가 256byte보다 이상 파일을 찾아라

$ find . -type f -size +256c


일반파일의 크기가 256byte보다 이하 파일을 찾아라

$ find . -type f -size -256c


Action
-exec : 외부명령 실행
-prune : 해당 결과 디렉토리는 검색 제외

ex)find [찾을 대상] [-option] [값] ([-Action] [명령])
※( )는 생략가능
./foo/bar 디렉토리는 제외하고, *.txt 파일을 찾아라

$ find . !\(-path './foo/bar' -prune\) -name "*.txt"

※AIX의 경우

$ find . ! -path ./foo/bar -name "*.txt"



./foo/bar와 ./dd/abc 디렉토리는 제외하고, *.txt 파일을 찾아라

$ find . !\(\(-path './foo/bar' -o -path './dd/abc'\) -prune\) -name "*.txt"


현재위치에서 하위의 모든 디렉토리 권한을 775로

$ find ./ -type d -exec chmod 775 {} \;


현재위치에서 하위의 모든 파일 권한을 644로

$ find ./ -type f -exec chmod 644 {} \;


모든 ".txt"파일에서 파일내용을 동시에 치환할때

$ find . -tpye f -name \*.txt -exec perl -pi -e 's/소스/타겟/g' {} \;


모든 ".txt"파일에서 파일명을 동시에 치환할때

$ find . -type f -name \*.txt |while read filename;do mv -f $filename `echo $filename | sed 's/소스/타겟/'`;done


A 파일을 B디렉토리로 무브

$ find . -name A파일명 -print | xargs -i mv {} B디렉토리명



728x90

'IT > OS (Unix Linux Windows)' 카테고리의 다른 글

[명령어]ln  (0) 2018.10.30
[명령어]split  (0) 2018.10.30
[명령어]touch  (0) 2018.10.30
[명령어]파일시스템 관련 df / du  (0) 2018.10.30
[명령어]압축관련 tar / gzip  (0) 2018.10.30

+ Recent posts