Linux I - 03. 리눅스 기본 명령어 (디렉토리 관리 명령어)
Linux I - 03. 리눅스 기본 명령어 (디렉토리 관리 명령어)
1. 'ls' 명령어
[root@CentOS /root]# ls -a 숨은 파일까지 포함하여 모든 파일을 볼수 있음
[root@CentOS /root]# ls -l 디렉토리인 경우, 디렉토리 내용을 보여주며, 파일인 경우, 속성 정보를 보여줌
[root@CentOS /root]# ls -R 해당 디렉토리와 하위 디렉토리 모든 내용을 보여줌
[root@CentOS /root]# ls -F 디렉토리 "/" 표시, 실행 파일 "*" 표시, 링크 파일 "@" 표시 해줌
[root@CentOS /root]# ls -i 해당 파일 inode 번호를 보여줌
[root@CentOS /root]# ls -n 파일 소유자와 그룹을 숫자로 보여줌
[root@CentOS /root]# ls -d 현재 디렉토리에 관한 정보를 보여줌
Ex1) 'ls' 명령어 기본 사용 방법
[root@CentOS ~]# echo $PS1
[\u@\h \W]\$
[root@CentOS ~]# PS1="[\u@\h \$PWD]# "
[root@CentOS /root]# cd ..
[root@CentOS /]#
[root@CentOS /]# mkdir test
[root@CentOS /]# cd test
[root@CentOS /test]#
[root@CentOS /test]# touch file1
[root@CentOS /test]# mkdir dir1
[root@CentOS /test]# touch dir1/file2
[root@CentOS /test]# ls -l
합계 4
drwxr-xr-x. 2 root root 4096 2015-12-22 21:18 dir1
-rw-r--r--. 1 root root 0 2015-12-22 21:18 file1
- |
파일 유형 ( - : 일반 파일, d : 디렉토리 파일) |
rw-r--r--. |
퍼미션 모드 |
1 |
하드 링크 수 |
root |
소유자 |
root |
그룹 |
0 |
파일 크기(Byte) |
2015-12-22 21:18 |
생성 및 수정 시간 |
file1 |
파일 이름 |
[root@CentOS /test]# ls -ld
drwxr-xr-x. 3 root root 4096 2015-12-22 21:18 .
[root@CentOS /test]# ls -l dir1
합계 0
-rw-r--r--. 1 root root 0 2015-12-22 21:18 file2
[root@CentOS /test]# ls -ld dir1
drwxr-xr-x. 2 root root 4096 2015-12-22 21:18 dir1
[root@CentOS /test]# ls -lR /test
/test:
합계 4
drwxr-xr-x. 2 root root 4096 2015-12-22 21:18 dir1
-rw-r--r--. 1 root root 0 2015-12-22 21:18 file1
/test/dir1:
합계 0
-rw-r--r--. 1 root root 0 2015-12-22 21:18 file2
Ex2) 'ls -a' 옵션 명령어
[root@CentOS /test]# cd
[root@CentOS /root]# pwd
/root
[root@CentOS /root]#
[root@CentOS /root]# ls -l
합계 100
-rw-------. 1 root root 1594 2015-12-18 22:14 anaconda-ks.cfg
-rw-r--r--. 1 root root 46035 2015-12-18 22:14 install.log
-rw-r--r--. 1 root root 10033 2015-12-18 22:12 install.log.syslog
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 공개
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 다운로드
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 문서
drwxr-xr-x. 2 root root 4096 2015-12-18 14:06 바탕화면
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 비디오
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 사진
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 음악
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 템플릿
[root@CentOS /root]# ls -la
합계 224
dr-xr-x---. 28 root root 4096 2015-12-22 21:14 .
dr-xr-xr-x. 26 root root 4096 2015-12-22 21:17 ..
-rw-------. 1 root root 1554 2015-12-21 19:46 .ICEauthority
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 .abrt
-rw-------. 1 root root 2564 2015-12-22 15:28 .bash_history
~~~ (중간 생략) ~~~
drwxr-xr-x. 2 root root 4096 2015-12-18 14:06 바탕화면
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 비디오
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 사진
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 음악
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 템플릿
Ex3) 'ls -F' 옵션 명령어
[root@CentOS /root]# cd /test
[root@CentOS /test]# rm -rf /test/*
[root@CentOS /test]# cp /etc/passwd file1
[root@CentOS /test]# ln -s file1 file2
[root@CentOS /test]# cp /bin/ls file3
[root@CentOS /test]# mkdir dir1
[root@CentOS /test]# ls -F
dir1/ file1 file2@ file3*
Ex4) 파일, 디렉토리만 출력하는 방법
[root@CentOS /test]# cd
[root@CentOS /root]# alias lsf='ls -l | grep "^-"'
[root@CentOS /root]# alias lsd='ls -l | grep "^d"'
[root@CentOS /root]# lsf
-rw-------. 1 root root 1594 2015-12-18 22:14 anaconda-ks.cfg
-rw-r--r--. 1 root root 46035 2015-12-18 22:14 install.log
-rw-r--r--. 1 root root 10033 2015-12-18 22:12 install.log.syslog
[root@CentOS /root]# lsd
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 공개
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 다운로드
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 문서
drwxr-xr-x. 2 root root 4096 2015-12-18 14:06 바탕화면
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 비디오
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 사진
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 음악
drwxr-xr-x. 2 root root 4096 2015-12-18 22:24 템플릿
2. 'mkdir' 명령어
Ex1) 'mkdir' 명령어
[root@CentOS /root]# cd /test
[root@CentOS /test]# rm -rf /test/*
[root@CentOS /test]# mkdir dir5
[root@CentOS /test]# ls
dir5
[root@CentOS /test]# mkdir dir6 dir7
[root@CentOS /test]# ls
dir5 dir6 dir7
Ex2) 'mkdir -p' 옵션 명령어
[root@CentOS /test]# mkdir dir4
[root@CentOS /test]# ls -l
합계 4
drwxr-xr-x. 2 root root 4096 2015-12-22 21:27 dir4
drwxr-xr-x. 2 root root 4096 2015-12-22 21:25 dir5
drwxr-xr-x. 2 root root 4096 2015-12-22 21:25 dir6
drwxr-xr-x. 2 root root 4096 2015-12-22 21:25 dir7
[root@CentOS /test]# mkdir dir4/dir2/dir1
mkdir: `dir4/dir2/dir1' 디렉토리를 만들 수 없습니다: 그런 파일이나 디렉터리가 없습니다
[root@CentOS /test]# mkdir -p dir4/dir2/dir1
[root@CentOS /test]# ls -R
.:
dir4 dir5 dir6 dir7
./dir4:
dir2
./dir4/dir2:
dir1
./dir4/dir2/dir1:
./dir5:
./dir6:
./dir7:
[root@CentOS /test]# tree
.
├── dir4
│ └── dir2
│ └── dir1
├── dir5
├── dir6
└── dir7
3. 'rmdir' 명령어
[root@CentOS /test]# ls
dir4 dir5 dir6 dir7
[root@CentOS /test]# rmdir dir5
[root@CentOS /test]# rmdir dir6 dir7
[root@CentOS /test]# ls
dir4
[root@CentOS /test]# rmdir dir4
rmdir: failed to remove `dir4': 디렉터리가 비어있지 않음
[root@CentOS /test]# rmdir -p dir4/dir2/dir1
[root@CentOS /test]# ls
[root@CentOS /test]# mkdir -p dir4/dir2/dir1
[root@CentOS /test]# rm -rf dir4/*
[root@CentOS /test]# ls
dir4
[root@CentOS /test]# tree
.
└── dir4
1 directory, 0 files
[root@CentOS /test]# mkdir -p dir4/dir2/dir1
[root@CentOS /test]# rm -rf dir4
[root@CentOS /test]# ls
[root@CentOS /test]# tree
.
0 directories, 0 files
[root@CentOS /test]# cd ..
[root@CentOS /]# rm -rf test