명령어

Date:     Updated:

카테고리:

태그:

history

  • 사용 명령어 목록 확인

    [root@localhost ~]# history
    

    화면 캡처 2022-09-28 084452

  • 최근 사용명령어 갯수 지정

    [root@localhost ~]# history 4
    

화면 캡처 2022-09-28 084755

mkdir, rmdir

  • mkdir

    • 디렉터리 생성

      [root@localhost ~]# mkdir /kh
      [root@localhost ~]# ls /
      

      화면 캡처 2022-09-28 085939

  • rmdir

    • 디렉터리 삭제

      [root@localhost ~]# rmdir /kh
      [root@localhost ~]# ls /
      

      화면 캡처 2022-09-28 090226

cd, pwd

  • cd

    • 경로 변경
    [root@localhost ~]# cd ./kh
    

    화면 캡처 2022-09-28 091406

  • pwd

    • 현재 작업중인 디렉터리 출력
    [root@localhost kh]# pwd
    

    화면 캡처 2022-09-28 091926

ls

  • 작업중인 디렉터리의 파일 / 디렉터리 목록
[root@localhost ~]# ls

화면 캡처 2022-09-28 093218

  • 숨김파일 표시 (파일명의 시작이 . 으로 표시된 파일)
[root@localhost ~]# ls -a

화면 캡처 2022-09-28 093538

  • 상세정보 확인
[root@localhost ~]# ls -l

화면 캡처 2022-09-28 093734

  • 숨김파일과 상세 정보 모두 확인

    [root@localhost ~]# ls -al
    

    화면 캡처 2022-09-28 093836

ㄹㅇㄴㅁ

date, rdate

  • date

    • 현재시간

      [root@localhost ~]# date
      

    화면 캡처 2022-09-29 082258

    • 시간 변경

      [root@localhost ~]# date -s '2022-11-11 11:11:11'
      

화면 캡처 2022-09-29 082427

  • rdate

    • 원격 시간 서버의 시간만 출력

      [root@localhost ~]# rdate -p time.bora.net
      

    화면 캡처 2022-09-29 082738

    • 원격 시간 서버와 동기화

      [root@localhost ~]# rdate -s time.bora.net
      

화면 캡처 2022-09-29 082919

which

  • 명령어의 실제 디렉터리 경로

    [root@localhost ~]# which 원하는명령어
    [root@localhost ~]# which ls
    

    화면 캡처 2022-09-29 083106

clear

  • 화면 지우기
[root@localhost ~]# clear
		또는
	  ctrl + l

화면 캡처 2022-09-29 083404

shutdown, reboot, halt

  • 바로 재시작

    [root@localhost ~]# shutdown -r now
    [root@localhost ~]# reboot
    [root@localhost ~]# init 6
    
  • 몇분 후 재시작

    [root@localhost ~]# shutdown -r +m
    [root@localhost ~]# shutdown -r +5
    

    화면 캡처 2022-09-29 084023

  • 지정된 시간 재시작

    [root@localhost ~]# shutdown -r 21:10
    

    화면 캡처 2022-09-29 084137

touch, cat ,echo

  • touch

    • 빈 파일 생성

      [root@localhost ~]# touch /root/a.txt
      

    화면 캡처 2022-09-29 085356

    • 이미 생성된 파일을 touch 하면 최근 접속 시간이 변경

      [root@localhost ~]# touch /root/a.txt
      [root@localhost ~]# ls -al /root/a.txt
      

화면 캡처 2022-09-29 085821

  • cat

    • 파일 읽기

      [root@localhost ~]# cat /etc/passwd
      

    화면 캡처 2022-09-29 091505

    • 파일 내용에 번호 출력

      [root@localhost ~]# cat -n /etc/passwd
      

      화면 캡처 2022-09-29 092551

    • cat 을 이용한 파일 생성

      [root@localhost ~]# cat > /root/c.txt
      내용   -> enter , ctrl + d
      

      화면 캡처 2022-09-29 093238

  • echo

    • 입력한 문자열 출력

      [root@localhost ~]# echo hi
      

      화면 캡처 2022-09-29 111857

    • echo 를 이용한 파일 생성

      [root@localhost ~]# echo hi > /root/hi.txt
      

      화면 캡처 2022-09-29 112019

      [root@localhost ~]# echo hihi > /root/hi.txt    -> 새로운 내용으로 같은 파일에 적용하면 내용이 덮어씌워진다
      

      화면 캡처 2022-09-29 112130

    • 파일에 내용 추가

      [root@localhost ~]# echo hello >> /root/hi.txt
      

      화면 캡처 2022-09-29 112509

head, tail

  • head

    • 파일 시작부터 기본 10행 출력

      [root@localhost ~]# head /etc/passwd
      

      화면 캡처 2022-09-29 112946

    • 원하는 n행 만큼 출력

      [root@localhost ~]# head -n /etc/passwd
      

      화면 캡처 2022-09-29 113124

  • tail

    • 파일 끝부터 출력

      [root@localhost ~]# tail /etc/passwd
      

      화면 캡처 2022-09-29 113254

    • 실시간 확인

      [root@localhost ~]# tail -f /var/log/messages
      

화면 캡처 2022-10-02 163715

more , less , pipe(|)

  • more

    • 스페이스바로 화면이동

      [root@localhost ~]# more /etc/passwd
      

      화면 캡처 2022-10-02 173654

  • less

    • 화살표로 화면 이동

      [root@localhost ~]# less /etc/passwd
      

      화면 캡처 2022-10-02 174040

  • pipe( )
    • 명령어 A 명령어 B
    • 명령어 A의 결과가 명령어 B의 argument(인자)

      [root@localhost ~]# ls -l /etc/ | more
      

      화면 캡처 2022-10-02 174230

grep

  • 특정한 단어를 검색

    [root@localhost ~]# cat > /root/hi.txt 
    root
    ktest
    ROOT
    KTEST
    root
    ktest
    ROOT
    KTEST
    [root@localhost ~]# grep root /root/hi.txt 
    

    화면 캡처 2022-10-02 195223

  • 검색된 행 갯수

    [root@localhost ~]# grep -c root /root/hi.txt
    

    화면 캡처 2022-10-02 195316

  • 대소문자 무시하고 검색

    [root@localhost ~]# grep -i root /root/hi.txt 
    

    화면 캡처 2022-10-02 195559

  • 해당 파일에서의 행번호

    [root@localhost ~]# grep -n root /root/hi.txt
    

    화면 캡처 2022-10-02 195644

cp, rm, mv

  • cp

    • 파일 복사

      [root@localhost ~]# mkdir /test
      [root@localhost ~]# cp /root/hi.txt /test
      [root@localhost ~]# ls /test/
      

      화면 캡처 2022-10-02 200354

      [root@localhost ~]# cp /root/hi.txt /test/hi2.txt
      [root@localhost ~]# ls /test/
      

      화면 캡처 2022-10-02 200449

    • 파일 복사시 허가권, 소유권

      [root@localhost ~]# ls -al /usr/bin/passwd
      

      화면 캡처 2022-10-02 211141

      [root@localhost ~]# cp /usr/bin/passwd /root/p
      [root@localhost ~]# ls -al /root/p
      

      화면 캡처 2022-10-02 211310

      [root@localhost ~]# cp -p /usr/bin/passwd /root/p
      [root@localhost ~]# ls -al /root/p
      

      화면 캡처 2022-10-02 211446

  • rm

    • 파일 삭제

      [root@localhost ~]# rm /test/hi2.txt
      

      화면 캡처 2022-10-02 201113

    • 디렉터리 삭제

      [root@localhost ~]# rm -r /test
      

      화면 캡처 2022-10-02 201521

    화면 캡처 2022-10-02 201542

    • 파일, 디렉터리 모두 한번에 삭제

      [root@localhost ~]# mkdir /test
      [root@localhost ~]# touch /test/hi.txt
      [root@localhost ~]# touch /test/h2i.txt
      [root@localhost ~]# rm -rf /test
      

      화면 캡처 2022-10-02 202239

  • mv

    • 이동

      root@localhost ~]# mkdir /test
      

      화면 캡처 2022-10-02 202636

    • 이동하면서 파일 이름 변경

      [root@localhost ~]# mv /test/hi.txt /root/hi2.txt
      

      화면 캡처 2022-10-02 203228

ln

  • 링크파일

  • i-node 번호

    • 파일에 부여되는 고유번호

      [root@localhost ~]# ls -li
      

      화면 캡처 2022-10-02 214052

  • hard link

    • i-node 번호는 같고 이름이 다르다

    • 파일만 사용

      [root@localhost ~]# echo hard > /test/hardlink.txt
      [root@localhost ~]# ls -li /test
      

      화면 캡처 2022-10-04 121453

      [root@localhost test]# ln /test/hardlink.txt /test/hard.txt
      [root@localhost test]# ls -li /test/
      

      화면 캡처 2022-10-04 121630

  • symbolic link

    • 파일, 디렉터리 모두가능

    • i-node 번호가 다름

    • 윈도우의 바로가기 느낌

      [root@localhost ~]# ln -s /test/hard.txt /test/symbolic.txt
      [root@localhost ~]# ls -li /test
      

      화면 캡처 2022-10-04 122123

  • link count

    • i-node 를 공유하는 파일의 갯수

      [root@localhost ~]# ls -li /test
      

      fdsafdsa

tar, gzip, bzip2

제목 없음

  • tar

    • 절대경로로 묶은 경우 -> 최상위 제외 경로까지 같이 묶인다

      [root@localhost ~]# tar cvf /root/123.tar /root/1 /root/2 /root/3
      

      화면 캡처 2022-10-06 101459

    • 묶음 해제

      [root@localhost ~]# tar xvf /root/123.tar
      

      화면 캡처 2022-10-06 104109

    • 묶음 파일 정보 확인

      [root@localhost ~]# tar tvf /root/123.tar
      

      화면 캡처 2022-10-06 104511

    • 상대 경로로 묶은 경우

      [root@localhost ~]# tar cvf /root/123.tar ./1 ./2 ./3
      

      화면 캡처 2022-10-06 104704

  • gzip

    • 묶여진 tar파일을 gzip 방식으로 압축

      [root@localhost ~]# gzip /root/123.tar
      

      화면 캡처 2022-10-06 110108

    • tar 파일+gzip 로 압축

      [root@localhost ~]# tar zcvf /root/123.tar.gz ./1 ./2 ./3
      

      화면 캡처 2022-10-06 111438

    • 압축해제

      [root@localhost ~]# tar zxvf /root/123.tar.gz
      

      화면 캡처 2022-10-06 111712

  • bzip2

    • 묶여진 tar파일을 bzip2 방식으로 압축

      [root@localhost ~]# tar jcvf /root/123.tar.bz ./1 ./2 ./3
      

      화면 캡처 2022-10-06 112041

    • 압축해제

      [root@localhost ~]# tar jxvf /root/123.tar.bz
      
  • 경로 지정하여 압축해제

    [root@localhost ~]# tar zxvf /root/123.tar.gz -C /home/ktest/
    

    화면 캡처 2022-10-09 153730


맨 위로 이동하기

centos 카테고리 내 다른 글 보러가기

댓글 남기기