본문 바로가기
문법/Linux

리눅스 명령어

by jungmin.park 2023. 10. 18.

ls(list)

  • ls [옵션] + 파일/디렉토리

[옵션]내용

-a(all) 해당경로 or 지정경로에서 숨겨진 파일이나 디렉토리를 보여준다.
-l(long) 자세한 내용을 출력한다.
소유자, 그룹, 파일크기, 수정일자, 파일이름
-h(human) K,M,G 단위를 사용하여 파일 크기를 사람이 보기 좋게 표시한다.
[centos@ip-172-31-0-74 ~]$ ls -a
.   .aws           .bash_logout   .bashrc  .rnd  WC       nlogger  package
..  .bash_history  .bash_profile  .pki     .ssh  install  openssl  prefix

[centos@ip-172-31-0-74 ~]$ ls -l
합계 4
drwxrwxr-x.  3 centos centos   26  3월  4 15:55 WC
drwxrwxr-x.  5 centos centos  206  3월  4 16:21 install
drwxr-xr-x.  4 centos centos   80  2월 23 14:01 nlogger
drwxrwxr-x.  2 centos centos   78  3월  4 18:04 openssl
drwxr-xr-x. 15 centos centos 4096  1월 11 16:23 package
drwxrwxr-x.  4 centos centos   39  1월 10 17:22 prefix

[centos@ip-172-31-0-74 ~]$ ls -al
합계 32
drwx------. 11 centos centos   215  3월  8 13:20 .
drwxr-xr-x.  3 root   root      20  9월  9  2020 ..
drwxrwxr-x.  2 centos centos    39  9월  9  2020 .aws
-rw-------.  1 centos centos 10260  3월  8 18:25 .bash_history
-rw-r--r--.  1 centos centos    18  8월  8  2019 .bash_logout
-rw-r--r--.  1 centos centos   193  8월  8  2019 .bash_profile
-rw-r--r--.  1 centos centos   231  8월  8  2019 .bashrc
drwxrw----.  3 centos centos    19  9월  9  2020 .pki
-rw-------.  1 centos centos  1024  3월  4 18:05 .rnd
drwx------.  2 centos centos    29  9월  9  2020 .ssh
drwxrwxr-x.  3 centos centos    26  3월  4 15:55 WC
drwxrwxr-x.  5 centos centos   206  3월  4 16:21 install
drwxr-xr-x.  4 centos centos    80  2월 23 14:01 nlogger
drwxrwxr-x.  2 centos centos    78  3월  4 18:04 openssl
drwxr-xr-x. 15 centos centos  4096  1월 11 16:23 package
drwxrwxr-x.  4 centos centos    39  1월 10 17:22 prefix

# ls -alh -> 모든 파일과 디렉토리를 사용자가 보기좋게 자세한 내용 출력
[centos@ip-172-31-0-74 ~]$ ls -alh
합계 32K
drwx------. 11 centos centos  215  3월  8 13:20 .
drwxr-xr-x.  3 root   root     20  9월  9  2020 ..
drwxrwxr-x.  2 centos centos   39  9월  9  2020 .aws
-rw-------.  1 centos centos  11K  3월  8 18:25 .bash_history
-rw-r--r--.  1 centos centos   18  8월  8  2019 .bash_logout
-rw-r--r--.  1 centos centos  193  8월  8  2019 .bash_profile
-rw-r--r--.  1 centos centos  231  8월  8  2019 .bashrc
drwxrw----.  3 centos centos   19  9월  9  2020 .pki
-rw-------.  1 centos centos 1.0K  3월  4 18:05 .rnd
drwx------.  2 centos centos   29  9월  9  2020 .ssh
drwxrwxr-x.  3 centos centos   26  3월  4 15:55 WC
drwxrwxr-x.  5 centos centos  206  3월  4 16:21 install
drwxr-xr-x.  4 centos centos   80  2월 23 14:01 nlogger
drwxrwxr-x.  2 centos centos   78  3월  4 18:04 openssl
drwxr-xr-x. 15 centos centos 4.0K  1월 11 16:23 package
drwxrwxr-x.  4 centos centos   39  1월 10 17:22 prefix

pwd(print working directory)

  • pwd [옵션] : 현재 작업 중인 디렉토리의 절대 경로를 출력하는 명령어
[root@ip-172-31-0-74 bin]# pwd
/home/centos/WC/agent-server/agent/bin

cd(change directory)

  • cd [옵션] + 경로(상대경로 or 절대 경로)

경로내용

cd ~ 홈 디렉토리로 이동한다.
cd - 홈 디렉토리로 이동 후 현재 경로를 출력한다.
cd / 루트 디렉토리(/)로 이동한다.
cd .. 상위 디렉토리로 이동한다.
cd ../.. 상위 디렉토리 이동 후 다시 상위 디렉토리로 이동한다.
# 현재경로
[centos@ip-172-31-0-74 conf]$ pwd
/home/centos/prefix/nginx/conf

[centos@ip-172-31-0-74 conf]$ cd ~
[centos@ip-172-31-0-74 ~]$ pwd
/home/centos

[centos@ip-172-31-0-74 ~]$ cd prefix/nginx/conf/
[centos@ip-172-31-0-74 conf]$ cd -
/home/centos

[centos@ip-172-31-0-74 conf]$ cd /
[centos@ip-172-31-0-74 /]$ ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

[centos@ip-172-31-0-74 nginx]$ pwd
/home/centos/prefix/nginx
[centos@ip-172-31-0-74 nginx]$ cd ..
[centos@ip-172-31-0-74 prefix]$ pwd
/home/centos/prefix

[centos@ip-172-31-0-74 conf]$ pwd
/home/centos/prefix/nginx/conf
[centos@ip-172-31-0-74 conf]$ cd ../..
[centos@ip-172-31-0-74 prefix]$ pwd
/home/centos/prefix

cp(copy file and directory)

  • cp [옵션] [복사 할 디렉토리/파일] [복사 될 디렉토리/파일]

[옵션]내용

-r, -R 디렉토리를 복사하는 경우 하위 디렉토리와 파일까지 모두 복사한다.
-f 복사에 대한 여부를 사용자에게 확인없이 강제로 복사한다.
덮어쓰기를 할 때 사용자에게 물어보지 않음.
[centos@ip-172-31-0-74 test]$ pwd
/home/centos/test
[centos@ip-172-31-0-74 test]$ ls
file1  file2  test.txt

[centos@ip-172-31-0-74 test]$ cp -f test.txt test_copy.txt
[centos@ip-172-31-0-74 test]$ tree
.
├── file1
├── file2
├── test.txt
└── test_copy.txt

[centos@ip-172-31-0-74 ~]$ pwd
/home/centos
[centos@ip-172-31-0-74 ~]$ cp test test_copy
cp: omitting directory `test'
[centos@ip-172-31-0-74 ~]$ cp -r test test_copy
[centos@ip-172-31-0-74 ~]$ ls
WC  install  nlogger  openssl  package  prefix  test  test_copy

mv( move[rename] file )

  • mv [옵션] [이동 할 파일] [이동 될 위치]

경로내용

파일1 파일2 : 이름바꾸기 파일1을 파일2로 이름을 변경함.
파일1 A디렉토리 파일1을 A 디렉토리 밑으로 이동시킨다.
파일1 파일2…. [이동 할 경로] 여러파일을 해당 경로로 이동시킨다.
mv -r * [이동 할 경로] 현재 위치의 모든 파일을 해당 경로로 이동시킨다.
이때, 숨김 파일은 이동되지 않는다.
디렉토리를 이동시킬때 하위 디렉토리까지 모두 이동해야 할 경우 -r 옵션을 사용한다.

touch

  • touch [옵션] [파일이름]
  • 파일의 생성과 파일의 날짜, 시간을 변경하는 명령어
  • 옵션없이 사용할 경우 서버의 현재시간으로 변경
  • 파일이 존재하지 않을 경우 크기가 0인 파일[임시파일]을 생성하며, 한번에 여러개의 파일을 만들 수 있다.

옵션내용

[파일이름] 빈 파일 생성
  • vi는 빈 파일을 wq로 저장하지 않으면 생성되지 않지만
  • touch는 빈 파일을 해당 명령어를 통해 생성할 수 있다.
-t [날짜,시간] [파일이름] 파일의 날짜를 수정할 경우 년,월,일,시간으로 입력
-m [파일이름] 서버시간으로 파일의 시간 변경
[centos@ip-172-31-0-74 test]$ touch text_file2.txt
[centos@ip-172-31-0-74 test]$ ls
file1  file2  test_copy.txt  text_file.txt  text_file2.txt
[centos@ip-172-31-0-74 test]$ cat text_file.txt
[centos@ip-172-31-0-74 test]$ touch -t 202203210600.45 text_file.txt
-rw-rw-r--.  1 centos centos    0  3월 21 06:00 text_file.txt

cat(concatenate files and print)

  • cat [옵션] [파일1] [파일2] ….
  • 파일을 점유하지 않고 볼 수 있는 명령어

옵션내용

file1, file2, file3 여러 개의 파일을 전달하여 파일 내용을 연속해서 출력
-n file1 행 번호를 표시한다.
[centos@ip-172-31-0-74 test]$ cat test_copy.txt
hi jungminpark
[centos@ip-172-31-0-74 test]$ cat -n test_copy.txt
     1  hi jungminpark

head

  • head [옵션] 파일

옵션

-n 숫자 [파일이름] 파일의 앞 부분을 숫자만큼 라인을 출력한다.
[파일1] [파일2] 2개의 파일을 출력하는데 출력시 해당 파일의 이름출력 후 내용이 출력된다.
[centos@ip-172-31-0-74 test]$ head test_copy.txt text_file.txt
==> test_copy.txt <==
hi jungminpark

==> text_file.txt <==

tail

  • tail [옵션] 파일

옵션

-n 숫자 [파일이름] 파일의 앞 부분을 숫자만큼 라인을 출력한다.
-n 숫자 [파일1] [파일2] 2개의 파일의 마지막 n 라인이 출력됨.
출력시 해당 파일의 이름출력 후 내용이 출력된다.
-f [파일] 파일의 변경사항을 모니터링
파일의 새 라인이 추가 될 경우 업데이트

more

  • more 파일1, 파일2,….

옵션

-숫자 [파일이름] 숫자줄씩 출력한다.
+/STRING 해당 값(STRING)이 있는 화면부터 출력한다.

버튼

스페이스바, Z 다음 페이지로 넘어간다.
b 이전 페이지로 돌아간다.
ENTER 한줄씩 넘어간다.
q 현재 명령을 종료한다.
d 반 페이지씩 넘어간다.

less

  • less 파일1, 파일2,….
  • 내용을 스크롤할 수 있도록 텍스트를 출력하는 명령어

file

  • file [옵션] [파일명]
  • 알 수 없는 파일의 정체가 궁금할 때 파일의 정보를 출력
[centos@ip-172-31-0-74 install]$ file *
nlogger.20200910.tgz:       gzip compressed data, from Unix, last modified: Thu Sep 10 16:30:17 2020
openssl-1.1.1g:             directory
openssl-1.1.1g.tar.gz:      gzip compressed data, from Unix, max compression
pcre-8.41:                  directory
pcre-8.41.tar.bz2:          bzip2 compressed data, block size = 900k
wisecollector.20210709.tgz: gzip compressed data, from Unix, last modified: Fri Jul  9 10:42:25 2021
zlib-1.2.11:                directory
zlib-1.2.11.tar.gz:         gzip compressed data, was "zlib-1.2.11.tar", from Unix, last modified: Mon Jan 16 02:36:58 2017, max compression

rmdir(remove empty directories)

  • rmdir [옵션] [디렉토리명]
  • 이때 삭제되는 디렉토리는 비어진 디렉토리여야 한다.

옵션

-p 디렉토리를 삭제할 때 상위 디렉토리도 함께 삭제한다.
다른 디렉토리나 파일이 존재할 경우 상위 디렉토리는 삭제되지 않는다.
[centos@ip-172-31-0-74 test]$ rmdir -p file1
rmdir: failed to remove `file1': 디렉터리가 비어있지 않음

rm (remove file / directory)

  • rm [옵션] [삭제 할 디렉토리 / 파일]
  • 한번 삭제한 파일에 대한 취소 명령어는 존재하지 않음. 신중히 삭제

옵션

-r 디렉토리 내부의 모든 내용을 삭제한다.
-f 강제로 파일이나 디렉토리를 삭제하고 대상이 없는 경우 메시지를 출력하지 않는다.
rm [삭제 대상1] [삭제 대상2] [삭제 대상3] .....
ex) rm test1.txt test2.txt test3.txt

현재 위치의 모든 파일 제거
ex) rm -rf *

현재 위치의 .txt로 끝나는 모든 파일 제거
rm *.txt

mkdir(make directories)

  • mkdir [옵션] [생성할 디렉토리 이름]

옵션

-p(parent) 상위 경로도 함께 생성되는 명령어
d1 d2 d3 여러 개의 디렉토리를 생성하고 싶을 때 생성하고자 하는 디렉토리 이름을 모두 입력
[centos@ip-172-31-0-74 test]$ ls
file1  file2  test_copy.txt  text_file.txt  text_file2.txt
[centos@ip-172-31-0-74 test]$ mkdir folder
[centos@ip-172-31-0-74 test]$ ls
file1  folder         text_file.txt
file2  test_copy.txt  text_file2.txt


[centos@ip-172-31-0-74 test]$ mkdir -p folder_test/folder2
[centos@ip-172-31-0-74 test]$ tree
.
├── file1
│   ├── test.origin.txt
│   └── test_copy.txt
├── file2
│   └── test.txt
├── folder
├── folder_test
│   └── folder2
├── test_copy.txt
├── text_file.txt
└── text_file2.txt

sudo

  • 일반 사용자가 root권한을 잠시 빌려 명령을 실행
  • su 계정명 : 현재 사용자를 로그아웃하지 않은 상태에서 다른 사용자의 계정으로 전환하는 명령어
  • su - 계정명 : 다른 사용자의 계정으로 완전히 전환하고, 전환한 사용자의 환경설정을 불러오는 명령어
    • su와 su-의 차이
      • su : 현재 계정의 환경변수를 유지한 채, 대상 계정으로 전환한다.
      • su - : 다른 사용자의 계정으로 전환하고 환경변수까지 그 계정의 상태로 완전히 전환

history

  • 명령어 이력을 보고 싶을 때 사용하는 명령어

sort( sort lines of text files )

  • sort [옵션] [파일명]

옵션

-r(reverse) 역순으로 정렬한다.
[centos@ip-172-31-0-74 test]$ cat sort.txt
b
c
d
e
a
f
[centos@ip-172-31-0-74 test]$ sort sort.txt

a
b
c
d
e
f
[centos@ip-172-31-0-74 test]$ sort -r sort.txt
f
e
d
c
b
a

uniq

  • uniq [ 옵션 ] [파일명]
  • 중복된 내용의 행이 연속으로 있으면 하나만 남기고 삭제한다.
  • 전체적으로 분산된 중복은 찾아내지 못한다. 따라서 정렬하여 순차적으로 만든뒤에 적용한다. ( sort와 같이 쓰기 좋음)

옵션

-c 같은 라인이 몇 번 나오는지 표시
[centos@ip-172-31-0-74 test]$ uniq sort.txt
b
c
d
e
a
f
a
b

ff
f

f
[centos@ip-172-31-0-74 test]$ uniq -c sort.txt
      1 b
      1 c
      1 d
      1 e
      1 a
      1 f
      7 a
      6 b
      1
      1 ff
     14 f
      1
      2 f
      2

grep

  • grep [옵션] [패턴] [파일이름]
  • 입력으로 전달된 파일의 내용에서 특정 문자열을 찾고자 할 때 사용하는 명령어

옵션

-v 매칭되는 PATTERN이 존재하지 않는 라인 선택
-r 하위 디렉토리를 포함한 모든 파일에서 문자열 검색
[centos@ip-172-31-0-74 test]$ cat test_copy.txt | grep hi
hi jungminpark
hi
hi
hi
[centos@ip-172-31-0-74 test]$ cat test_copy.txt | grep -v hi
hello
jungmin
park
hello
ls
cd
cd
[centos@ip-172-31-0-74 ~]$ cat test/* | grep -r jungmin
cat: test/file1: 디렉터리입니다
cat: test/file2: 디렉터리입니다
cat: test/folder: 디렉터리입니다
cat: test/folder_test: 디렉터리입니다
prefix/nginx/logs/access.2022031113:61.33.35.145 - - [11/Mar/2022:13:41:31 +0900] 
"GET /nlog/log/event?s=jmin_tistory&u=https%3A%2F%2Fjung-mmmmin.tistory.com%2F&a=Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20Win64%3B%20x64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F99.0.4844.51%20Safari%2F537.36&c=nth_screen_title%3Djungmin%2520blog%3B%20nth_screen_id%3D%252F%3B%20nth_resolution%3D1707x1067%3B%20nth_locale_country%3Dkr%3B%20nth_locale_lang%3Dko%3B%20nth_sdk%3DWEB%3B%20nth_pcid%3Dcc557348-90f9-9e01-249b-a2a129dc284c-1639457127619&v=1691871880 HTTP/1.1" 200 0 "https://jung-mmmmin.tistory.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36"

awk

  • awk [옵션] [액션]

옵션

-F 확장된 정규 표현식으로 필드구분자를 지정한다. 다중 필드 구분자 사용 가능함.
203.42.46.70 
[02/Jan/2022:17:51:08 +0900] 
"GET https://dreamfare.flyasiana.com/I/AU/EN/DreamFareList.do?_n_p01=PC&_n_p02=AU&_n_p03=EN&_n_request=https://dreamfare.flyasiana.com/I/AU/EN/DreamFareList.do&_n_title=Oz%20Dream%20Fare%E2%94%82Asiana%20Airlines&_n_referrer=https://flyasiana.com/&_n_sid=TF.AU.dreamfare.flyas  HTTP/1.1"
 
"https://flyasiana.com/" 200 0 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36" 
"PCID=16411090684193499663407; PCID_publish=NEW; n_ss=1920x1080; n_cs=en-gb;"
[wiselog: /FTP/LJK/logs/asiana/weblog1/wlo2018]$ 
zcat *flyasiana.com/access*.*.mod.gz | awk -F'"' '{print $2}' | more

GET https://dreamfare.flyasiana.com/I/AU/EN/DreamFareList.do?_n_p01=PC&_n_p02=AU&_n_p03=EN&_n_request=http
s://dreamfare.flyasiana.com/I/AU/EN/DreamFareList.do&_n_title=Oz%20Dream%20Fare%E2%94%82Asiana%20Airlines&
_n_referrer=https://flyasiana.com/&_n_sid=TF.AU.dreamfare.flyasiana.com HTTP/1.1
GET https://flyasiana.com/C/AU/EN/index?_n_p01=PC&_n_p02=AU&_n_p03=EN&_n_request=https://flyasiana.com/C/A
U/EN/index&_n_title=ASIANA%20AIRLINES&_n_referrer=https://flyasiana.com/&_n_sid=TF.AU.flyasiana.com HTTP/1
.1
GET https://flyasiana.com/click_event?_n_p01=PC&_n_p02=AU&_n_p03=EN&pagecode=01_TOP_03&_n_request=https://
flyasiana.com/click_event%3F_n_p01%3DPC%26_n_p02%3DAU%26_n_p03%3DEN%26pagecode%3D01_TOP_03&_n_title=ASIANA
+AIRLINES&_n_referrer=https://flyasiana.com/C/AU/EN/index&_n_sid=TF.AU.flyasiana.com HTTP/1.1
GET https://flyasiana.com/I/AU/EN/viewLogin.do?callType=IBE&menuId=CM201802220000728453&_n_p01=PC&_n_p02=A
U&_n_p03=EN&_n_request=https://flyasiana.com/I/AU/EN/viewLogin.do%253FcallType%253DIBE%2526menuId%253DCM20
1802220000728453&_n_title=Log-in%E2%94%82Asiana%20Airlines&_n_referrer=https://flyasiana.com/C/AU/EN/index
&_n_sid=TF.AU.flyasiana.com HTTP/1.1
GET https://flyasiana.com/click_event?_n_p01=PC&_n_p02=AU&_n_p03=EN&_n_p04=ID&&_n_request=https://flyasian
a.com/click_event%3F_n_p01%3DPC%26_n_p02%3DAU%26_n_p03%3DEN%26_n_p04%3DID%26&_n_title=Log-in%E2%94%82Asian
a+Airlines&_n_referrer=https://flyasiana.com/I/AU/EN/viewLogin.do%3FcallType%3DIBE%26menuId%3DCM2018022200
00728453&_n_sid=TF.AU.flyasiana.com HTTP/1.1
GET https://flyasiana.com/C/AU/EN/index?_n_p01=PC&_n_p02=AU&_n_p03=EN&_n_request=https://flyasiana.com/C/A
U/EN/index&_n_title=ASIANA%20AIRLINES&_n_referrer=https://flyasiana.com/&_n_sid=TF.AU.flyasiana.com HTTP/1
.1

alias

  • alias 별명 = ‘명령어정의’
  • unalias 명령어별칭 : 등록된 Alias(별칭)을 삭제
  • 복잡한 명령어를 간소화하여 다른 이름으로 사용할 수 있도록 해주는 쉘내부 명령어
  • 하지만 이 방법은 시스템을 재부팅하고나면 다시 초기화되므로 매번 적용해야 하는 불편함이 있다.
  • 특정 파일에 설정해두면 매번 부팅시마다 자동으로 적용되어 쉽게 사용할 수 있다.
alias build='ssh -i "build.pem" ubuntu@ec2-15-164-89-243.ap-northeast-2.compute.amazonaws.com'
cd ~/Desktop

find

  • find [옵션][경로][…]
  • 리눅스에서 파일 및 디렉토리를 검색할 때 사용하는 명령어

옵션

-name 지정된 문자열 패턴에 해당하는 파일 검색
[centos@ip-172-31-0-74 ~]$ find ./test -name "test*"
./test
./test/file1/test_copy.txt
./test/file1/test.origin.txt
./test/file1/test.txt
./test/file2/test.txt
./test/folder/test_copy.txt
./test/test_copy.txt

[centos@ip-172-31-0-74 ~]$ find . -name "test*" -type d
./install/zlib-1.2.11/contrib/testzlib
./install/zlib-1.2.11/test
./install/pcre-8.41/testdata
./install/openssl-1.1.1g/test
./install/openssl-1.1.1g/test/testutil
find: ‘./prefix/nginx/client_body_temp’: 허가 거부
find: ‘./prefix/nginx/proxy_temp’: 허가 거부
find: ‘./prefix/nginx/fastcgi_temp’: 허가 거부
find: ‘./prefix/nginx/uwsgi_temp’: 허가 거부
find: ‘./prefix/nginx/scgi_temp’: 허가 거부
./WC/agent-server/jdk/sample/jmx/jmx-scandir/test
./WC/agent-server/base/flume/flume/docs/apidocs/org/apache/flume/shared/kafka/test
./WC/agent-server/base/flume/apache-flume-1.9.0-bin/docs/apidocs/org/apache/flume/shared/kafka/test
./package/jdk/sample/jmx/jmx-scandir/test
./package/base/flume/flume/docs/apidocs/org/apache/flume/shared/kafka/test
./package/base/flume/apache-flume-1.9.0-bin/docs/apidocs/org/apache/flume/shared/kafka/test
./test
./test_copy

du

  • du [옵션] [파일]
  • 디렉터리별로 디스크 사용량을 알려주는 명령어
  •  

옵션

-a(all) 디렉토리뿐만 아니라 파일들의 사용량까지 표기
-s(summarize) 용량의 합계를 보여줌
-h(--human-readable) 사람이 읽기 좋게 파일단위로 표시
38640   ./package/base/flume/apache-flume-1.9.0-bin/docs
111604  ./package/base/flume/apache-flume-1.9.0-bin
4       ./package/base/flume/._bin
4       ./package/base/flume/._apache-flume-1.9.0-bin
4       ./package/base/flume/._data
4       ./package/base/flume/._flume
265060  ./package/base/flume
4       ./package/base/._flume
265068  ./package/base
4       ./package/agent.cfg
674488  ./package
4       ./test/file1/test_copy.txt
4       ./test/file1/test.origin.txt
4       ./test/file1/test.txt
12      ./test/file1
4       ./test/file2/test.txt
4       ./test/file2
0       ./test/text_file.txt
0       ./test/text_file2.txt
4       ./test/folder/test_copy.txt
4       ./test/folder
0       ./test/folder_test/folder2
0       ./test/folder_test
4       ./test/sort.txt
4       ./test/test_copy.txt
28      ./test
0       ./test_copy/file1
0       ./test_copy/file2
4       ./test_copy/test_1.txt
4       ./test_copy/test_2.txt
8       ./test_copy
[centos@ip-172-31-0-74 ~]$ du -s
du: cannot read directory `./prefix/nginx/client_body_temp': 허가 거부
du: cannot read directory `./prefix/nginx/proxy_temp': 허가 거부
du: cannot read directory `./prefix/nginx/fastcgi_temp': 허가 거부
du: cannot read directory `./prefix/nginx/uwsgi_temp': 허가 거부
du: cannot read directory `./prefix/nginx/scgi_temp': 허가 거부
2237124 .


[centos@ip-172-31-0-74 ~]$ du -s
109M    ./package/base/flume/apache-flume-1.9.0-bin
259M    ./package/base/flume
259M    ./package/base
659M    ./package
12K     ./test/file1
4.0K    ./test/file2
4.0K    ./test/folder
0       ./test/folder_test/folder2
0       ./test/folder_test
28K     ./test
0       ./test_copy/file1
0       ./test_copy/file2
8.0K    ./test_copy
2.2G    .

shutdown

  • shutdown [옵션] [시간]
  • reboot : 시스템 재부팅
    • -f : 시스템 강제 재부팅

옵션

-r 종료 후 재부팅
-h shutdown 이 완료된 후 시스템을 종료
shutdown -h now            지금 즉시 종료
shutdown -h +3              3분후 종료
shutdown -r now             지금 즉시 재부팅
shutdown -r 14:00           14시에 재부팅
shutdown now                유지보수 모드로 전환

rdate

  • 리눅스의 시간을 timeserver와 동기화하는 명령어
  • 리눅스는 서버로 운영되고 있는 경우가 많은데 서버 시간은 서버에서 동작하는 여러 서비스에 영향을 주게 되기 때문에 항상 정확한 시간 정보를 유지하는 것이 좋다.
  • 정확한 시간 정보 유지를 위해 타임서버(Time Server)의 시간 정보를 불러와서 기준 시간으로 삼을 수 있다.
  • rdate [옵션] [호스트]
rdate -s time.bora.net

date

  • date + format 형식
$ date "+%Y-%m-%d %H:%M:%S"
2020-04-12 13:21:10

$ date "+%Y-%m-%d %I:%M:%S %p"
2020-04-12 13:21:10

$ date -d "-1 days"
2020. 04. 11. (토) 13:23:05 KST

nginx 로드밸런싱 옵션

  • 시스템 구성도에서 살펴보면 proxy 앞 단에 두대가 뒤에 있는 로깅서버로 로드밸런싱이 필요하다.
  • 로드밸런싱을 위한 nginx.conf 파일 수정이 필요
  •  
  •  
     
    http { # options upstream app(름) { ip_hash; server 10.41.101.18:8080; server 10.41.101.48:8080; } include mime.type; default_type application/octet-stream; server { listen 80; ... (생략) location / { proxy_pass http://app; proxy_set_header X-Real-IP $remote_addr; ...(생략) } 
http {
  # options
    upstream app(이름) {
      ip_hash;
      server 106.41.101.18:8080;
      server 106.41.101.48:8080;
    }
    
    include mime.type;
    default_type application/octet-stream;
    
    server {
      listen 80;
        ... (생략)
        
      location / {
        proxy_pass http://app;
        proxy_set_header X-Real-IP $remote_addr;
        ...(생략)
      }
    }
    
}

 

Nginx 설치 오류 발생

  1. 처음 zlib, pcre, openssl 설치 후
    1. ./configure --with-zlib=../../install/zlib-1.2.11 --with-pcre=../../install/pcre-8.44 --with-openssl=/usr/bin --prefix=/app/datastory/nginx --user=datastory 으로 컴파일
      1. 해당 openssl 경로설정 오류 https 설정이후 ssl 관련 모듈이 없다는 오류 메세지가 발생.
    2. 이를 재컴파일이 필요
    3. 재 컴파일시 해당 경로는 변경되는 것, 새로 설치되는 것과 상관없이 처음부터 끝까지 재지정해줘야한다.
    4. ./configure --with-zlib=/app/datastory/install/zlib-1.2.11 --with-pcre=/app/datastory/install/pcre-8.44 --with-openssl=/app/datastory/install/openssl-1.1.1g --with-http_stub_status_module --with-http_ssl_module --prefix=/app/datastory/nginx --user=datastory
    5. -with-http_stub_status_module --with-http_ssl_module : 만약 재컴파일을 하여도 ssl 모듈이 없다는 오류가 발생한다면 모듈을 설치하는 옵션도 추가로 지정해주어야 한다.