728x90

절대경로에서 파일 및 파일경로만 추출하기

 ex) basename [절대경로]
     절대경로에서 파일의 이름을 출력해라

$ basename /shome/i8/test/123
123


 ex) dirname [절대경로]
     절대경로에서 해당파일의 디렉토리 경로를 출력해라 

$ dirname /shome/i8/test/123
/shome/i8/test


728x90

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

[UNIX]DNS Looping  (0) 2018.11.08
[java 관련 명령어] jinfo / jstat / jstack / jmap  (0) 2018.11.06
[명령어]ln  (0) 2018.10.30
[명령어]split  (0) 2018.10.30
[명령어]find  (0) 2018.10.30
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
728x90

touch
 개요
 크기가 0인 새 파일을 생성하거나, 파일의 타임스탬프를 현재 시간으로 변경합니다.

 Options
 -t [YYYYMMDDhhmm]: 해당 파일스탬프로 변경

 ex)touch [-option] [대상 디렉토리 및 파일]
     dd라는 파일의 파일스탬프를 다음과 같이 변경 2017년08월28일20시

$ touch -t 201708282000 dd


728x90

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

[명령어]split  (0) 2018.10.30
[명령어]find  (0) 2018.10.30
[명령어]파일시스템 관련 df / du  (0) 2018.10.30
[명령어]압축관련 tar / gzip  (0) 2018.10.30
[명령어]lsof  (0) 2018.10.24
728x90

df
 개요
 시스템의 마운트된 디스크 사용량 확인

 Options
 -k : 킬로바이트 단위로 현재 남은 용량을 확인 
 -h : 보기 좋게 보여줌 -> HPUX는 bdf라는 명령어로 대체

 ex)df [-option] 
     마운트된 디스크 사용량 확인

$ df -h


  
du
 개요
 특정 디렉토리 기준으로 디스크 사용량 확인

 Options
 -a : 하위 디렉토리에 포함된 파일까지 보여줌
  -s : 총 사용량을 확인
 -h : 보기 좋게 보여줌

 ex)du [-option] [대상 디렉토리 및 파일]
     현재 디렉토리 사용량 확인

$ du -s .


728x90

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

[명령어]find  (0) 2018.10.30
[명령어]touch  (0) 2018.10.30
[명령어]압축관련 tar / gzip  (0) 2018.10.30
[명령어]lsof  (0) 2018.10.24
[명령어]netstat  (0) 2018.10.24
728x90

tar
 개요
 확장명 tar로 파일을 묶거나 풀 수 있다.
 ※절대경로로 묶은 파일은 절대경로로 풀리는 것을 유의
 
 Options
 c : 새로운 묶음을 만든다.
 x : 묶인 파일을 푼다.
 t : 뿍음을 풀기 전에 묶인 경로를 보여준다.
 C : 묶음을 풀때 지정된 디렉터리에 푼다. 지정하지 않으면 동일한 디렉터리에 묶음이 풀린다.(x와 함께 사용)
 f : 묶음 파일 이름 지정
 v : 묶이거나 풀리는 과정을 보여준다.
 J : tar + xz
 z : tar + gzip
 j : tar + bzip2

 ex)tar [-option]
     파일 묶기

$ tar -cvf [파일명.tar] [대상 디렉토리 or 파일]


     파일 풀기

$ tar -xvf [파일명.tar]

 
     파일 보기

$ tar -tvf [파일명.tar]


gzip
 개요
 기본적으로 UNIX / LINUX 환경에서 사용하는 압축 프로그램

 Options
 -c : 압축결과를 출력하고 원본파일 유지
 -d : 압축 해제
 -f : 강제 압축
 -l : 압축 파일의 정보 출력
 -r : 디렉토리를 지정시 하위 포함된 디렉토리 및 파일까지 압축
 -t : 압축 테스트
 -v : 압축 할 때 자세한 정보 출력

 ex)gzip [-option] [대상]
     파일 압축

$ gzip [대상]


     파일 풀기

$ gunzip [대상.gz]


728x90

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

[명령어]touch  (0) 2018.10.30
[명령어]파일시스템 관련 df / du  (0) 2018.10.30
[명령어]lsof  (0) 2018.10.24
[명령어]netstat  (0) 2018.10.24
정규표현식의 사용(작성중)  (0) 2018.10.17
728x90

lsof(LiSt Open File)
 개요
 현재 System에서 돌아가는 모든 Process에 의해서 Open 된 파일들에 대한 정보를 보여준다.
 리눅스와 유닉스는 추상화된 파일 시스템(VFS - Virtual File System)을 사용하므로 네트워크 소켓, 라이브러리등 모두 파일로 처리되므로 lsof를 통해 상세한 정보를 확인 할 수 있음.

 항목 설명
  COMMAND : 현재 실행되고 있는 명령어
  PID : 프로세스 ID
  USER : 실행한 사용자
  FD : File Descriptor

  FD 값
    cwd : current working directory
    rtd : root directory
    mem : memory-mapped file
    txt : program text
    r : read access
    w : write access
    u : read and write access

  TYPE : 파일 종류

  Type 값
    DIR : 디렉토리
    CHR : character special file
    FIFO : 선입선출
    REG : 일반파일
    unix : 유닉스 도메인 소켓(TCP/UDP 보다 속도가 빠름)

  DEVICE : 장치 번호
  SIZE/OFF : 파일의 크기나 오프셋
  NODE : 노드 번호
  NAME : 파일명

 Options
 -c : 해당 명령어가 사용하고 있는 파일들에 대해서 출력한다.
 -t : 현재 동작되고 있는 프로세서의 PID를 출력한다.
 -p : 해당 pid가 참조하고 있는 프로그램과 파일들을 출력
 -i : 현재 열려있는 소켓들에 대해서 출력한다.
 +D : 특정 디렉토리 이하의 열려있는 파일들에 대해서 출력한다.
 
 ex)lsof [-option] 값
    특정 포트 사용 조회 > lsof -i TCP:[PORT number]

#/usr/local/bin/lsof -i TCP:11736
COMMAND   PID  USER   FD   TYPE             DEVICE  SIZE/OFF NODE NAME
java    14121 jeus  136u  IPv4 0xe0000005f8f0ad00     0t917  TCP 127.0.0.1:30044->127.0.0.1:11736 (ESTABLISHED)
java    14395 jeus  113u  IPv4 0xe00000054a97c980       0t0  TCP *:11736 (LISTEN)


    특정 PID 사용 조회 > lsof -p [PID]

#/usr/local/bin/lsof -p 8791     
COMMAND  PID  USER   FD   TYPE             DEVICE SIZE/OFF      NODE NAME
java    8791 jeus  cwd    DIR           2,0x3a99     1024        31 /logs/jeus/dump
java    8791 jeus  txt    REG             64,0x3   150676    197133 /opt/java6/jre/bin/IA64N/java
java    8791 jeus  mem    REG             64,0x3   411676     26289 /usr/lib/nls/loc/hpux32/locales.3/ko_KR.eucKR
java    8791 jeus    0r  FIFO 0xe0000003ea675a88      0t0 123437066 
java    8791 jeus    6u  unix             64,0x3      0t0    189233 /var/spool/sockets/pwgr/client8791 (0x1508e680)
java    8791 jeus  107u   CHR              192,0      0t0       174 /dev/random
java    8791 jeus  115u  IPv4 0xe00000054ba85100      0t0       TCP *:11861 (LISTEN)
java    8791 jeus  118u  IPv4 0xe00000045a464100  0t10042       TCP 127.0.0.1:28859->127.0.0.1:11736 (ESTABLISHED)


    특정 디렉토리 이하의 열린 파일 조회 > lsof +D [디렉토리]

#/usr/local/bin/lsof +D /src/web/WEB-INF/lib
COMMAND   PID  USER   FD   TYPE   DEVICE SIZE/OFF     NODE NAME
java    20808 jeus  142u   REG 2,0x3a98   621839  2777605 /src/web/WEB-INF/lib/BarCode.jar
java    20808 jeus  143u   REG 2,0x3a98     1455  2777871 /src/web/WEB-INF/lib/CardDes.jar
java    20808 jeus  144u   REG 2,0x3a98     8566  2777894 /src/web/WEB-INF/lib/CertVerifierClient_v2.1.1.jar
java    20808 jeus  145u   REG 2,0x3a98    25441  2778032 /src/web/WEB-INF/lib/D3SocketClient.jar


    특정 명령어가 사용하는 파일 조회 > lsof -c [명령어]

#/usr/local/bin/lsof -c tail
COMMAND   PID  USER   FD   TYPE   DEVICE  SIZE/OFF   NODE NAME
tail    22378 jeus  cwd    DIR 2,0x3a99      5120  11323 /logs/online-log/
tail    22378 jeus  txt    REG   64,0x3     74900    296 /usr/bin/tail
tail    22378 jeus  mem    REG   64,0x3    411676  26289 /usr/lib/nls/loc/hpux32/locales.3/ko_KR.eucKR
tail    22378 jeus  mem    REG   64,0x3   5094520  58648 /usr/lib/hpux32/libc.so.1
tail    22378 jeus  mem    REG   64,0x3     86960  26399 /usr/lib/nls/loc/hpux32/methods.1/libHP15.so
tail    22378 jeus  mem    REG   64,0x3    191436 209651 /usr/lib/hpux32/uld.so
tail    22378 jeus  mem    REG   64,0x3     76736 209649 /usr/lib/hpux32/libdl.so.1
tail    22378 jeus  mem    REG   64,0x3   1170536 209648 /usr/lib/hpux32/dld.so
tail    22378 jeus    0u   REG 2,0x3a99   5633482  80738 /logs/online-log/2018debug.log
tail    22378 jeus    1u   STR  157,0x7 0t9456571    807 /dev/pts/7->ldterm->ptem->pts
tail    22378 jeus    2u   STR  157,0x7 0t9456571    807 /dev/pts/7->ldterm->ptem->pts
tail    22378 jeus    3r   REG   64,0x3       661  24497 /usr/lib/nls/msg/ko_KR.eucKR/tail.cat


    TCP 포트 11736번을 사용하는 PID 리스트 조회  > lsof -t -i TCP:11736

#/usr/local/bin/lsof -t -i TCP:11736
11726
14121
14395
14448


    lsof를 이용한 특정 user의 프로세스 강제 종료 > kill -9 `lsof -t -u [유저명]`

 

728x90

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

[명령어]touch  (0) 2018.10.30
[명령어]파일시스템 관련 df / du  (0) 2018.10.30
[명령어]압축관련 tar / gzip  (0) 2018.10.30
[명령어]netstat  (0) 2018.10.24
정규표현식의 사용(작성중)  (0) 2018.10.17
728x90

netstat
 개요
 TCP/IP 프로토콜 진단 시 사용

 결과에 대한 항목 설명
  Proto : 현재 사용한 프로토콜 종류
 Recv-Q : 원격 응용 프로그램으로부터 수신하여 버퍼에 저장한 데이터의 양
 Send-Q : 원격 응용 프로그램으로부터 전송하기 위하여 송신 버퍼에 저장한 데이터의 양
  Local Address : 현재 열려 있는 사용자 컴퓨터의 IP/호스트 네임과 사용중인 포트
  Foreign Address : 현재 사용자의 컴퓨터에 접속되어 있는 IP/호스트 네임과 사용중인 포트
  State : 연결상태

  State 값
    LISTEN : 연결을 위하여 접속을 기다리는 상태
    SYN_SENT : 클라이언트 프로그램이 원격 호스트에 연결을 요청한 상태
    SYN_RECV : 서버가 클라이언트 프로그램으로부터 연결요청을 받아 클라이언트에 응답을 하였지만 아직 클라이언트의 확인 메시지를 받지 않은 상태
    ESTABLISHED : 현재 연결되어 있는 상태
    FIN_WAIT1 : 한쪽 응용 프로그램이 연결 종료를 요청한 상태
    CLOSE_WAIT : 연결 종료 메시지를 수신하고 그에 대한 확인 메시지를 보낸 상태
    FIN_WAIT2 : 로컬에서 종결 메시지를 전송하였고 원격 호스트로부터 이에 대한 확인 메시지를 수신하였지만, 원격 응용 프로그램이 작업을 종료하지 않아 원격 호스트의 종결 메시지를 기다리는 상태
    LAST_ACK : 원격으로부터 종결 요청을 받고 로컬에서도 회선 종결에 합의한 상태
    TIME_WAIT : 연결은 종료되었지만 마지막 조욜 확인 메시지를 재전송할 경우를 감안하여 당분간 소켓정보를 유지하고 있는 상태
    CLOSED : 완전히 연결이 종료된 상태

 Options
  -a : 모든 연결 및 수신 대기 포트를 표시합니다.
  -b : 각 연결 또는 수신 대기 포트를 만드는 데 관련된 실행 프로그램을 표시합니다. 
  -e : 이더넷 통계를 표시합니다. 이 옵션은 -s 옵션과 같이 사용될 수 있습니다.
  -n : 주소 및 포트 번호를 숫자 형식으로 표시합니다.
  -o : 각 연결의 소유자 프로세스 ID를 표시합니다.
  -p : 프로토콜 지정한 프로토콜에 해당되는 연결을 표시합니다.
  -r : 라우팅 테이블을 표시합니다.
  -s : 각 네트워크 프로토콜(IP, TCP, UDP, ICMP)에 대한 통계 정보를 출력합니다.

 ex)netstat [-option]
   열려있는 모든 포트

$ netstat -an
Active Internet connections (including servers)
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
tcp        0      0  127.0.0.1.49473    127.0.0.1.13901     ESTABLISHED
tcp        0      0  127.0.0.1.13901       *.*                   LISTEN

728x90

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

[명령어]touch  (0) 2018.10.30
[명령어]파일시스템 관련 df / du  (0) 2018.10.30
[명령어]압축관련 tar / gzip  (0) 2018.10.30
[명령어]lsof  (0) 2018.10.24
정규표현식의 사용(작성중)  (0) 2018.10.17
728x90

정규표현식이란 우리가 Unix/Linux 환경에서 힘들지 않고 편하게 사용하려면 꼭 숙지해야 하는 내용이다.


이걸 모르면 손이 고생하는 수 밖에 없다.


정규표현식
  • vi, ex, grep, egrep, sed, awk 등의 모든 버전에서 사용 가능
메타문자기능사용 예사용 예 설명
^ 행의 시작 지시자 /^love/ love로 시작하는 모든 행과 대응
$ 행의 끝 지시자 /love$/ love로 끝나는 모든 행과 대응
. 하나의 문자와 대응 /l..e/ l 다음에 두 글자가 나오고 e로 끝나는 문자열을 포함하는 행과 대응
* 선행 문자와 같은 문자의 0개 혹은 임의개수와 대응 /*love/ 임의 개수의 공백 문자 후에 love로 끝나는 문자열을 포함한 행과 대응
[] [] 사이의 문자 집합 중 하나와 대응 /[Ll]ove/ Love나 love를 포함하는 행과 대응
[x-y] [] 사이의 문자범위내에의 한 문자와 대응 [A-Z]ove/ A부터 Z까지 한 문자가 ove로 끝나는 경우와 대응 
[^ ] 문자집합에 속하지 않는 한 문자와 대응 /[^A-Z]/ A와 Z 사이의 범위에 포함되지 않는 한  문자와 대응
\ 메타문자로 사용하고 싶지 않은 경우 /love\./ love가 마침표(.)로 끝나는 경우와 대응.
 일반적으로 .는 임의의 한 문자를 의미

\<

 단어의 시작 지시자

 /\<love

 love로 시작하는 단어를 포함하는 행과 대응

\>

 단어의 끝 지시자

 /love\>/

 love로 끝나는 단어를 포함하는 행과 대응
\(..\) 다음 사용을 위해 태그를 붙인다.

/\(lov\)able\1er/

 9개 태그를 쓸 수 있다.



728x90

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

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

+ Recent posts