2. 21 (수) Linux 정리 - 기본 명령어
----------------------------------------------------------------------------
Putty
login as: root
→ 루트계정 로그인 시도
root@192.168.10.240's password:
→ 현재 서버 컴퓨터의 id 출력 및 패스워드 입력 창
Last login: Tue Feb 20 13:51:50 2018 from 192.168.10.236
→ 마지막 로그인 정보
[root@centos ~]#
→ 프롬프트라고 한다.
----------------------------------------------------------------------------
기본 틀
# command (-단일문자옵션) (--다중문자옵션)
* 실습 환경
OS : SULinux OS
hostname : su1-localhost
1) 파일 정보 출력
- ls -a
→ .으로 시작하는 파일은 히든파일 / 히든파일을 포함하여 출력
[root@su1-localhost ~]# ls -a
. .bash_logout .cshrc anaconda-ks.cfg install.log
.. .bash_profile .tcshrc bin install.log.syslog
.bash_history .bashrc .viminfo conf
- ls -l
→ 파일에 대한 여러 정보를 함께 출력
[root@su1-localhost ~]# ls -l
합계 56
-rw------- 1 root root 2714 3월 15 12:53 anaconda-ks.cfg
drwxr-xr-x 7 root root 4096 3월 15 12:48 bin
drwxr-xr-x 2 root root 4096 3월 15 12:48 conf
-rw-r--r-- 1 root root 21235 3월 15 12:53 install.log
-rw-r--r-- 1 root root 0 3월 15 12:35 install.log.syslog
* 응용 예시
ls -a -l 혹은 ls -al(단일문자취급)
-> 히든파일을 포함한 파일의 여러 정보를 출력
[root@su1-localhost ~]# ls -al
합계 124
drwxr-x--- 4 root root 4096 3월 15 14:44 .
drwxr-xr-x 23 root root 4096 3월 16 09:14 ..
-rw------- 1 root root 1252 3월 15 14:44 .bash_history
-rw-r--r-- 1 root root 24 7월 14 2008 .bash_logout
-rw-r--r-- 1 root root 224 3월 15 12:40 .bash_profile
-rw-r--r-- 1 root root 208 3월 15 12:40 .bashrc
-rw-r--r-- 1 root root 100 7월 14 2008 .cshrc
-rw-r--r-- 1 root root 129 7월 14 2008 .tcshrc
-rw------- 1 root root 4685 3월 15 14:44 .viminfo
-rw------- 1 root root 2714 3월 15 12:53 anaconda-ks.cfg
drwxr-xr-x 7 root root 4096 3월 15 12:48 bin
drwxr-xr-x 2 root root 4096 3월 15 12:48 conf
-rw-r--r-- 1 root root 21235 3월 15 12:53 install.log
-rw-r--r-- 1 root root 0 3월 15 12:35 install.log.syslog
----------------------------------------------------------------------------
디렉토리 : 파일을 담고 있는 공간
1) 디렉토리의 표현 방법
1. 절대경로 - ex) /tmp/a.txt
2. 상대경로 - ex) ./a.txt ('./'는 현재위치를 의미)
상대경로의 시작은 항상 ./로 시작
* 정리
/ : 최상위 root 디렉토리 (절대경로 표현의 기준)
./ : 현재 디렉토리 (상대경로 표현의 기준이며, 생략이 가능)
../ : 현재 디렉토리의 상위 디렉토리
~/ : 각 사용자의 홈 디렉토리
디렉토리는 파일의 일종이며, 다음의 특성을 갖는다.
- 이름 : 최대 255자
- 대소문자 구별 (혼선을 피하기 위해 대문자와 소문자를 통일하여 사용함)
데이터베이스에선 구별없지만, 무결성을 위해 통일하는 것이 좋음.
애시던트 : 보안적인 사고(problem)
- 확장자 없음
----------------------------------------------------------------------------
기초명령어
- cd [이동할 디렉토리명]
디렉토리를 이동하는 명령어
단순 cd만 입력 시, 홈 디렉토리로 이동
[root@su1-localhost ~]# cd bin
↓
[root@su1-localhost bin]#
작업 공간이 ~ (홈디렉토리)에서 bin 디렉토리로 이동한 모습이다.
- pwd
현재 위치한 디렉토리를 절대경로 표현으로 출력
[root@su1-localhost bin]# pwd
/root/bin
→ /의 하위 디렉토리 root의 하위 디렉토리인 bin 디렉토리
// /디렉토리 포함 파일
bin - 일반 명령어 sbin - 시스템 명령어 etc - 모든 환경설정 파일
- rmdir
디렉토리가 비워져있을 경우 디렉토리삭제
조건 때문에 잘 쓰지 않음. (디렉토리가 무조건 비워져있어야 함)
- mkdir
디렉토리 생성
-p 옵션 사용 시, 하위 디렉토리까지 한 번에 생성.
* 유의점 : 디렉토리를 표현 시 마지막에 / 꼭 붙여주기 (습관을 들이기 위함)
[root@su1-localhost bin]# mkdir test
[root@su1-localhost bin]# ls ./
apm license.txt ssu_release su_mailuser system_check
apmtools log su_backup su_traffic system_check_init
chkrootkit quota_check su_dbuser su_usersetup test
conf sbin su_domain su_vhost
[root@su1-localhost bin]# rmdir test
- ls
현재 디렉토리의 목록을 출력
옵션
굉장히 자주쓰임
-a, --all : 숨겨진 파일의 목록까지 출력
-l : 파일에 대한 정보를 자세히 출력
적당히 쓰임
-R : 하위 디렉토리 내용까지 출력
-h : 사람이 이해하기 쉽게 파일의 크기 함께 출력
-k : Kb 단위로 파일 크기 출력
-i : 파일의 inode 번호를 함께 출력
[root@su1-localhost ~]# ls
anaconda-ks.cfg bin conf install.log install.log.syslog
[root@su1-localhost ~]# ls -alki
합계 124
1014817 drwxr-x--- 4 root root 4 3월 15 14:44 .
2 drwxr-xr-x 23 root root 4 3월 16 09:14 ..
1014935 -rw------- 1 root root 2 3월 15 14:44 .bash_history
1014820 -rw-r--r-- 1 root root 1 7월 14 2008 .bash_logout
1014821 -rw-r--r-- 1 root root 1 3월 15 12:40 .bash_profile
1014822 -rw-r--r-- 1 root root 1 3월 15 12:40 .bashrc
1014823 -rw-r--r-- 1 root root 1 7월 14 2008 .cshrc
1014824 -rw-r--r-- 1 root root 1 7월 14 2008 .tcshrc
1014936 -rw------- 1 root root 5 3월 15 14:44 .viminfo
1014934 -rw------- 1 root root 3 3월 15 12:53 anaconda-ks.cfg
1014825 drwxr-xr-x 7 root root 4 3월 16 09:47 bin
1014835 drwxr-xr-x 2 root root 4 3월 15 12:48 conf
1014818 -rw-r--r-- 1 root root 21 3월 15 12:53 install.log
1014819 -rw-r--r-- 1 root root 0 3월 15 12:35 install.log.syslog
- 리다이렉트
: 표준 입출력 지시자
> : 표준 출력 지시자
- command > 파일 : 명령 결과를 파일로 저장
>> : 추가 표준 출력 지시자
- command >> 파일 : 명령 결과를 파일에 추가
< : 표준 입력 지시자
- command < 파일 : 파일의 내용을 명령의 입력 값으로 사용
[root@su1-localhost ~]# echo test1 > test1.txt
[root@su1-localhost ~]# cat test1.txt
test1
[root@su1-localhost ~]# ls -alik >> test2.txt
[root@su1-localhost ~]# cat test2.txt
합계 128
1014817 drwxr-x--- 4 root root 4 3월 16 09:52 .
2 drwxr-xr-x 23 root root 4 3월 16 09:14 ..
1014935 -rw------- 1 root root 2 3월 15 14:44 .bash_history
1014820 -rw-r--r-- 1 root root 1 7월 14 2008 .bash_logout
1014821 -rw-r--r-- 1 root root 1 3월 15 12:40 .bash_profile
1014822 -rw-r--r-- 1 root root 1 3월 15 12:40 .bashrc
1014823 -rw-r--r-- 1 root root 1 7월 14 2008 .cshrc
1014824 -rw-r--r-- 1 root root 1 7월 14 2008 .tcshrc
1014936 -rw------- 1 root root 5 3월 15 14:44 .viminfo
1014934 -rw------- 1 root root 3 3월 15 12:53 anaconda-ks.cfg
1014825 drwxr-xr-x 7 root root 4 3월 16 09:47 bin
1014835 drwxr-xr-x 2 root root 4 3월 15 12:48 conf
1014818 -rw-r--r-- 1 root root 21 3월 15 12:53 install.log
1014819 -rw-r--r-- 1 root root 0 3월 15 12:35 install.log.syslog
1014937 -rw-r--r-- 1 root root 1 3월 16 09:52 test1.txt
1014938 -rw-r--r-- 1 root root 0 3월 16 09:52 test2.txt
[root@su1-localhost ~]# head < test1.txt
test1
→ 그래서 head라는 명령어를 사용해보았더니 결과가 나오는 것을 확인할 수 있었다.
→ echo 명령어의 결과가 출력되지 않는 이유는..???
* head : 파일의 머리, 즉 앞부분을 확인하는 명령어이며, 행을 기준으로 기본 10행 단위의
파일 내용을 출력해준다.
----------------------------------------------------------------------------
Putty
login as: root
→ 루트계정 로그인 시도
root@192.168.10.240's password:
→ 현재 서버 컴퓨터의 id 출력 및 패스워드 입력 창
Last login: Tue Feb 20 13:51:50 2018 from 192.168.10.236
→ 마지막 로그인 정보
[root@centos ~]#
→ 프롬프트라고 한다.
----------------------------------------------------------------------------
기본 틀
# command (-단일문자옵션) (--다중문자옵션)
* 실습 환경
OS : SULinux OS
hostname : su1-localhost
1) 파일 정보 출력
- ls -a
→ .으로 시작하는 파일은 히든파일 / 히든파일을 포함하여 출력
[root@su1-localhost ~]# ls -a
. .bash_logout .cshrc anaconda-ks.cfg install.log
.. .bash_profile .tcshrc bin install.log.syslog
.bash_history .bashrc .viminfo conf
- ls -l
→ 파일에 대한 여러 정보를 함께 출력
[root@su1-localhost ~]# ls -l
합계 56
-rw------- 1 root root 2714 3월 15 12:53 anaconda-ks.cfg
drwxr-xr-x 7 root root 4096 3월 15 12:48 bin
drwxr-xr-x 2 root root 4096 3월 15 12:48 conf
-rw-r--r-- 1 root root 21235 3월 15 12:53 install.log
-rw-r--r-- 1 root root 0 3월 15 12:35 install.log.syslog
* 응용 예시
ls -a -l 혹은 ls -al(단일문자취급)
-> 히든파일을 포함한 파일의 여러 정보를 출력
[root@su1-localhost ~]# ls -al
합계 124
drwxr-x--- 4 root root 4096 3월 15 14:44 .
drwxr-xr-x 23 root root 4096 3월 16 09:14 ..
-rw------- 1 root root 1252 3월 15 14:44 .bash_history
-rw-r--r-- 1 root root 24 7월 14 2008 .bash_logout
-rw-r--r-- 1 root root 224 3월 15 12:40 .bash_profile
-rw-r--r-- 1 root root 208 3월 15 12:40 .bashrc
-rw-r--r-- 1 root root 100 7월 14 2008 .cshrc
-rw-r--r-- 1 root root 129 7월 14 2008 .tcshrc
-rw------- 1 root root 4685 3월 15 14:44 .viminfo
-rw------- 1 root root 2714 3월 15 12:53 anaconda-ks.cfg
drwxr-xr-x 7 root root 4096 3월 15 12:48 bin
drwxr-xr-x 2 root root 4096 3월 15 12:48 conf
-rw-r--r-- 1 root root 21235 3월 15 12:53 install.log
-rw-r--r-- 1 root root 0 3월 15 12:35 install.log.syslog
----------------------------------------------------------------------------
디렉토리 : 파일을 담고 있는 공간
1) 디렉토리의 표현 방법
1. 절대경로 - ex) /tmp/a.txt
2. 상대경로 - ex) ./a.txt ('./'는 현재위치를 의미)
상대경로의 시작은 항상 ./로 시작
* 정리
/ : 최상위 root 디렉토리 (절대경로 표현의 기준)
./ : 현재 디렉토리 (상대경로 표현의 기준이며, 생략이 가능)
../ : 현재 디렉토리의 상위 디렉토리
~/ : 각 사용자의 홈 디렉토리
디렉토리는 파일의 일종이며, 다음의 특성을 갖는다.
- 이름 : 최대 255자
- 대소문자 구별 (혼선을 피하기 위해 대문자와 소문자를 통일하여 사용함)
데이터베이스에선 구별없지만, 무결성을 위해 통일하는 것이 좋음.
애시던트 : 보안적인 사고(problem)
- 확장자 없음
----------------------------------------------------------------------------
기초명령어
- cd [이동할 디렉토리명]
디렉토리를 이동하는 명령어
단순 cd만 입력 시, 홈 디렉토리로 이동
[root@su1-localhost ~]# cd bin
↓
[root@su1-localhost bin]#
작업 공간이 ~ (홈디렉토리)에서 bin 디렉토리로 이동한 모습이다.
- pwd
현재 위치한 디렉토리를 절대경로 표현으로 출력
[root@su1-localhost bin]# pwd
/root/bin
→ /의 하위 디렉토리 root의 하위 디렉토리인 bin 디렉토리
// /디렉토리 포함 파일
bin - 일반 명령어 sbin - 시스템 명령어 etc - 모든 환경설정 파일
- rmdir
디렉토리가 비워져있을 경우 디렉토리삭제
조건 때문에 잘 쓰지 않음. (디렉토리가 무조건 비워져있어야 함)
- mkdir
디렉토리 생성
-p 옵션 사용 시, 하위 디렉토리까지 한 번에 생성.
* 유의점 : 디렉토리를 표현 시 마지막에 / 꼭 붙여주기 (습관을 들이기 위함)
[root@su1-localhost bin]# mkdir test
[root@su1-localhost bin]# ls ./
apm license.txt ssu_release su_mailuser system_check
apmtools log su_backup su_traffic system_check_init
chkrootkit quota_check su_dbuser su_usersetup test
conf sbin su_domain su_vhost
[root@su1-localhost bin]# rmdir test
[root@su1-localhost bin]# ls ./
apm license.txt ssu_release su_mailuser system_check
apmtools log su_backup su_traffic system_check_init
chkrootkit quota_check su_dbuser su_usersetup
conf sbin su_domain su_vhost
→ test 디렉토리의 생성과 삭제
----------------------------------------------------------------------------- ls
현재 디렉토리의 목록을 출력
옵션
굉장히 자주쓰임
-a, --all : 숨겨진 파일의 목록까지 출력
-l : 파일에 대한 정보를 자세히 출력
적당히 쓰임
-R : 하위 디렉토리 내용까지 출력
-h : 사람이 이해하기 쉽게 파일의 크기 함께 출력
-k : Kb 단위로 파일 크기 출력
-i : 파일의 inode 번호를 함께 출력
[root@su1-localhost ~]# ls
anaconda-ks.cfg bin conf install.log install.log.syslog
[root@su1-localhost ~]# ls -alki
합계 124
1014817 drwxr-x--- 4 root root 4 3월 15 14:44 .
2 drwxr-xr-x 23 root root 4 3월 16 09:14 ..
1014935 -rw------- 1 root root 2 3월 15 14:44 .bash_history
1014820 -rw-r--r-- 1 root root 1 7월 14 2008 .bash_logout
1014821 -rw-r--r-- 1 root root 1 3월 15 12:40 .bash_profile
1014822 -rw-r--r-- 1 root root 1 3월 15 12:40 .bashrc
1014823 -rw-r--r-- 1 root root 1 7월 14 2008 .cshrc
1014824 -rw-r--r-- 1 root root 1 7월 14 2008 .tcshrc
1014936 -rw------- 1 root root 5 3월 15 14:44 .viminfo
1014934 -rw------- 1 root root 3 3월 15 12:53 anaconda-ks.cfg
1014825 drwxr-xr-x 7 root root 4 3월 16 09:47 bin
1014835 drwxr-xr-x 2 root root 4 3월 15 12:48 conf
1014818 -rw-r--r-- 1 root root 21 3월 15 12:53 install.log
1014819 -rw-r--r-- 1 root root 0 3월 15 12:35 install.log.syslog
- 리다이렉트
: 표준 입출력 지시자
> : 표준 출력 지시자
- command > 파일 : 명령 결과를 파일로 저장
>> : 추가 표준 출력 지시자
- command >> 파일 : 명령 결과를 파일에 추가
< : 표준 입력 지시자
- command < 파일 : 파일의 내용을 명령의 입력 값으로 사용
[root@su1-localhost ~]# echo test1 > test1.txt
[root@su1-localhost ~]# cat test1.txt
test1
[root@su1-localhost ~]# ls -alik >> test2.txt
[root@su1-localhost ~]# cat test2.txt
합계 128
1014817 drwxr-x--- 4 root root 4 3월 16 09:52 .
2 drwxr-xr-x 23 root root 4 3월 16 09:14 ..
1014935 -rw------- 1 root root 2 3월 15 14:44 .bash_history
1014820 -rw-r--r-- 1 root root 1 7월 14 2008 .bash_logout
1014821 -rw-r--r-- 1 root root 1 3월 15 12:40 .bash_profile
1014822 -rw-r--r-- 1 root root 1 3월 15 12:40 .bashrc
1014823 -rw-r--r-- 1 root root 1 7월 14 2008 .cshrc
1014824 -rw-r--r-- 1 root root 1 7월 14 2008 .tcshrc
1014936 -rw------- 1 root root 5 3월 15 14:44 .viminfo
1014934 -rw------- 1 root root 3 3월 15 12:53 anaconda-ks.cfg
1014825 drwxr-xr-x 7 root root 4 3월 16 09:47 bin
1014835 drwxr-xr-x 2 root root 4 3월 15 12:48 conf
1014818 -rw-r--r-- 1 root root 21 3월 15 12:53 install.log
1014819 -rw-r--r-- 1 root root 0 3월 15 12:35 install.log.syslog
1014937 -rw-r--r-- 1 root root 1 3월 16 09:52 test1.txt
1014938 -rw-r--r-- 1 root root 0 3월 16 09:52 test2.txt
[root@su1-localhost ~]# echo < test1.txt
→ echo는 표준입력지시자의 결과가 나오지 않는다.
test1
→ 그래서 head라는 명령어를 사용해보았더니 결과가 나오는 것을 확인할 수 있었다.
→ echo 명령어의 결과가 출력되지 않는 이유는..???
* head : 파일의 머리, 즉 앞부분을 확인하는 명령어이며, 행을 기준으로 기본 10행 단위의
파일 내용을 출력해준다.
----------------------------------------------------------------------------
댓글
댓글 쓰기