자료실

홈 / 고객센터 / 자료실

CentOS 8 리눅스 기본 명령어

기본정보
  • 글쓴이
  • 고객지원팀
  • 조회수
  • 934회
상세내용
Contents | 리눅스 기본 명령어
Ⅰ. 기본 명령어

 

 

 

1. 기본 명령어
▷ ls

    → LiSt의 약어. 해당 디렉터리에 있는 파일의 목록을 나열 합니다.

# 현재 디렉터리의 파일 목록
[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg

# /home/magicpipe 디렉터리의 목록
[root@localhost ~]# ls /home/magicpipe/
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos

# 현재 디렉터리의 목록 (숨김 파일 포함)
[root@localhost ~]# ls -a
.   .bash_history  .bash_profile  .cache   .cshrc  .esd_auth  anaconda-ks.cfg
..  .bash_logout   .bashrc        .config  .dbus   .tcshrc    initial-setup-ks.cfg

# 현재 디렉터리의 목록을 자세히 보여줌
[root@localhost ~]# ls -l
total 8
-rw-------. 1 root root 1459 Sep 14 17:25 anaconda-ks.cfg
-rw-r--r--. 1 root root 1569 Sep 14 17:42 initial-setup-ks.cfg

# 현재 디렉터리의 목록을 자세히 보여줌 (숨김 파일 포함)
[root@localhost ~]# ls -al
total 36
dr-xr-x---.  5 root root  222 Sep 14 18:19 .
dr-xr-xr-x. 17 root root  224 Sep 14 17:05 ..
-rw-------.  1 root root 1229 Sep 25 16:18 .bash_history
-rw-r--r--.  1 root root   18 May 12  2019 .bash_logout
-rw-r--r--.  1 root root  176 May 12  2019 .bash_profile
-rw-r--r--.  1 root root  176 May 12  2019 .bashrc
drwx------.  3 root root   19 Sep 14 17:41 .cache
drwx------.  4 root root   31 Sep 14 18:10 .config
-rw-r--r--.  1 root root  100 May 12  2019 .cshrc
drwx------.  3 root root   25 Sep 14 17:41 .dbus
-rw-------.  1 root root   16 Sep 14 18:10 .esd_auth
-rw-r--r--.  1 root root  129 May 12  2019 .tcshrc
-rw-------.  1 root root 1459 Sep 14 17:25 anaconda-ks.cfg
-rw-r--r--.  1 root root 1569 Sep 14 17:42 initial-setup-ks.cfg

# 확장자가 cfg인 목록을 자세히 보여줌
[root@localhost ~]# ls -al *.cfg
anaconda-ks.cfg  initial-setup-ks.cfg

# 앞 글자가 'a'인 것의 목록을 자세히 보여줌
[root@localhost ~]# ls -al a*
-rw-------. 1 root root 1459 Sep 14 17:25 anaconda-ks.cfg
 

 

▷ cd

    → Change Directory의 약어. 디렉터리를 이용하는 명령 입니다.

# 현재 사용자의 홈 디렉터리로 이동
[root@localhost ~]# cd /
[root@localhost /]#

# magicpipe 사용자의 홈 디렉터리로 이동
[root@localhost ~]# cd ~magicpipe
[root@localhost magicpipe]#

# 바로 상위 디렉터리로 이동
[root@localhost magicpipe]# cd ..
[root@localhost home]#

# 절대경로 이동 방법 : /root/test 디렉터리로 이동
[root@localhost home]# cd /root/test
[root@localhost test]#

# 상대경로 이동 방법 : 현재 디렉터리 상위로 이동 후 다시 하위에 있는 test2로 이동
[root@localhost test]# cd ../test2
[root@localhost test2]#
 

 

▷ pwd

    → Print Working Directory의 약어. 현재 디렉터리의 전체 경로를 화면에 보여 줍니다.

# 현재 경로의 디렉터리 경로 출력
[root@localhost test2]# pwd
/root/test2
 

 

▷ rm

    → ReMove의 약자로 파일이나 디렉터리를 삭제 합니다.

# 파일 삭제
[root@localhost test2]# rm a.txt
rm: remove regular empty file 'a.txt'? y

# 파일 삭제 시 확인 메시지 나옴
[root@localhost test2]# rm -i b.txt
rm: remove regular empty file 'b.txt'? y

# 파일 삭제 시 확인하지 않고 바로 삭제
[root@localhost test2]# rm -f c.txt
[root@localhost test2]#

# 해당 디렉터리 삭제 시 확인 메시지 나옴
[root@localhost test2]# rm -r test3
rm: remove directory 'test3'? y
[root@localhost test2]#

# 해당 디렉터리 삭제 시 확인하지 않고 바로 삭제
[root@localhost test2]# rm -rf test4
[root@localhost test2]#
 

 

▷ cp

    → CoPy의 약어. 파일이나 디렉터리를 복사 합니다. 새로 복사한 파일은 복사한 사용자의 소유가 됩니다.

# d.txt를 a.txt 이름으로 복사
[root@localhost test2]# cp d.txt a.txt
[root@localhost test2]# ls -al
total 0
drwxr-xr-x. 2 root root  45 Sep 28 15:36 .
dr-xr-x---. 7 root root 247 Sep 28 15:23 ..
-rw-r--r--. 1 root root   0 Sep 28 15:36 a.txt
-rw-r--r--. 1 root root   0 Sep 28 15:31 d.txt
-rw-r--r--. 1 root root   0 Sep 28 15:31 e.txt

# test5 디렉터리를 test6 이름으로 복사
[root@localhost test2]# cp -r test5 test6
[root@localhost test2]# ls -al
total 0
drwxr-xr-x. 4 root root  71 Sep 28 15:37 .
dr-xr-x---. 7 root root 247 Sep 28 15:23 ..
-rw-r--r--. 1 root root   0 Sep 28 15:36 a.txt
-rw-r--r--. 1 root root   0 Sep 28 15:31 d.txt
-rw-r--r--. 1 root root   0 Sep 28 15:31 e.txt
drwxr-xr-x. 2 root root   6 Sep 28 15:37 test5
drwxr-xr-x. 2 root root   6 Sep 28 15:37 test6
 

 

▷ touch

    → 크기가 0 인 새 파일을 생성하거나, 이미 파일이 존재한다면 파일의 최종 수정 시간을 변경 합니다.

# f.txt 빈 파일을 생성
[root@localhost test2]# touch f.txt
[root@localhost test2]# ls -al
total 0
drwxr-xr-x. 4 root root  84 Sep 28 15:41 .
dr-xr-x---. 7 root root 247 Sep 28 15:23 ..
-rw-r--r--. 1 root root   0 Sep 28 15:36 a.txt
-rw-r--r--. 1 root root   0 Sep 28 15:31 d.txt
-rw-r--r--. 1 root root   0 Sep 28 15:31 e.txt
-rw-r--r--. 1 root root   0 Sep 28 15:41 f.txt
drwxr-xr-x. 2 root root   6 Sep 28 15:37 test5
drwxr-xr-x. 2 root root   6 Sep 28 15:37 test6
 

 

▷ mv

    → MoVe의 약어. 파일이나 디렉터리의 이름을 변경하거나 다른 디렉터리로 옮길 때 사용 합니다.

# f.txt 파일을 /root/test 로 이동
[root@localhost test2]# mv f.txt /root/test/
[root@localhost test2]# ls -al /root/test
total 0
drwxr-xr-x. 2 root root  19 Sep 28 15:42 .
dr-xr-x---. 7 root root 247 Sep 28 15:23 ..
-rw-r--r--. 1 root root   0 Sep 28 15:41 f.txt

# a.txt 파일을 b.txt 파일로 이름 변경 후 /root/test 로 이동
[root@localhost test2]# mv a.txt /root/test/b.txt
[root@localhost test2]# ls -al /root/test
total 0
drwxr-xr-x. 2 root root  32 Sep 28 15:44 .
dr-xr-x---. 7 root root 247 Sep 28 15:23 ..
-rw-r--r--. 1 root root   0 Sep 28 15:36 b.txt
-rw-r--r--. 1 root root   0 Sep 28 15:41 f.txt
 


 
 

▷ mkdir

    → MaKe DIRectory의 약어. 새로운 디렉터리를 생성 합니다.

# test7 디렉터리 생성
[root@localhost test2]# mkdir test7
[root@localhost test2]# ls -al
total 0
drwxr-xr-x. 5 root root  84 Sep 28 15:46 .
dr-xr-x---. 7 root root 247 Sep 28 15:23 ..
-rw-r--r--. 1 root root   0 Sep 28 15:31 d.txt
-rw-r--r--. 1 root root   0 Sep 28 15:31 e.txt
-rw-r--r--. 1 root root   0 Sep 28 15:46 g.txt
drwxr-xr-x. 2 root root   6 Sep 28 15:37 test5
drwxr-xr-x. 2 root root   6 Sep 28 15:37 test6
drwxr-xr-x. 2 root root   6 Sep 28 15:46 test7

# test8 아래 하위 test8_node 디렉터리 일괄 생성
[root@localhost test2]# mkdir -p test8/test8_node
[root@localhost test2]# cd test8/test8_node
[root@localhost test8]# pwd
/root/test2/test8
 

 

▷ rmdir

    → ReMove DIRectory의 약어. 디렉토리를 삭제 하는 명령어 입니다.

# test7 디렉터리 삭제
[root@localhost test2]# rmdir test7
 

 

▷ cat

    → conCATenate의 약어로, 파일의 내용을 화면에 보여 줍니다.

# d.txt 파일 내용 보기
[root@localhost test2]# cat d.txt
hello world!

# d.txt와 e.txt 파일 한번에 보기
[root@localhost test2]# cat d.txt e.txt
hello world!
hello linux!
 

 

▷ head, tail

    → 텍스트 형식의 파일의 앞 10행 또는 마지막 10행만 화면에 출력 합니다.

# 해당 파일의 앞 10행 출력
[root@localhost ~]# head anaconda-ks.cfg
#version=RHEL8
ignoredisk --only-use=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
# Use graphical install
graphical
# Use CDROM installation media
cdrom
# Keyboard layouts

# 해당 파일의 앞 3행만 출력
[root@localhost ~]# head -3 anaconda-ks.cfg
#version=RHEL8
ignoredisk --only-use=sda
autopart --type=lvm

# 해당 파일의 뒷 10행 출력
[root@localhost ~]# tail anaconda-ks.cfg
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

# 해당 파일의 뒷 3행만 출력
[root@localhost ~]# tail -3 anaconda-ks.cfg
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
 

 

▷ more

    → 텍스트 형식의 파일을 페이지 단위로 화면에 출력 합니다.

# 해당 문서의 페이지별로 문서 보기
[root@localhost ~]# more anaconda-ks.cfg
#version=RHEL8
ignoredisk --only-use=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
# Use graphical install
...

# 해당 문서의 30행 이후 페이지별로 문서 보기
[root@localhost ~]# more +30 anaconda-ks.cfg
user --name=magicpipe --password=$6$W4uFmTTf9Tp7LYu3$jGsNHm.1UR0Zd42QdZFgtOFSQc.i/9xaVly5xWhx28KHSCc
IvgxSrJT9i3Phe0Q.2igbyH8e/uFgTD1dodUp51 --iscrypted --gecos="magicpipe"
%packages
@^graphical-server-environment
kexec-tools
...
 

 

▷ less

    → 'more' 명령어와 용도가 비슷 합니다.

# 해당 문서의 페이지별로 문서 보기
[root@localhost ~]# less anaconda-ks.cfg
#version=RHEL8
ignoredisk --only-use=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
# Use graphical install
...

# 해당 문서의 30행 이후 페이지별로 문서 보기
[root@localhost ~]# less +30 anaconda-ks.cfg
user --name=magicpipe --password=$6$W4uFmTTf9Tp7LYu3$jGsNHm.1UR0Zd42QdZFgtOFSQc.i/9xaVly5xWhx28KHSCc
IvgxSrJT9i3Phe0Q.2igbyH8e/uFgTD1dodUp51 --iscrypted --gecos="magicpipe"
%packages
@^graphical-server-environment
kexec-tools
...
 

 

▷ file

    → 해당 파일이 어떤 종류의 파일인지를 표시 합니다.

# 파일 형태 확인
[root@localhost ~]# file anaconda-ks.cfg
anaconda-ks.cfg: ASCII text
 

 

▷ clear

    → 현재 사용 중인 터미널 화면을 지워줍니다.

자료실

유용한 자료들을 모아두었습니다.