본문 바로가기

프로그래밍/Linux-Server

linux 2강 리눅스 기초 명령어

반응형

리눅스에서 터미널 실행한다. (프로그램 - 즐켜찾기 -터미널)

 

가. ls (LiSt, 파일 목록)

1) ls

2) ls -la : 자세하게 보기

 

.현재 디렉토리

.. 상위 디렉토리

d 디렉토리 

- 파일

사용권한(permission)

r Read (읽고)

w Write (쓰기)

x eXecute (실행)

 

dr-xr-x---

d => 디렉토리

현재 그룹 기타 사용자

r-x  / r-x / ---

 

3) ls -la | more

파일 목록이 많을 경우 먼저 한페이지를 보여주고 엔터를 치면 한 줄씩 보여줌

ls -la | more

 

 

나. cd(ChangeDirectory) 

[root@localhost ~]#

root => 현재 사용자가 root임

~ => 사용자의 홈디렉토리

리눅스는 윈도우의 c: d: 와 같은 드라이버가 없다. 

/로 시작한다. 

1) cd ~ 홈디렉토리로 이동

root 사용자의 홈디렉토리 : /root

user 사용자의 홈디렉토리 : /home/아이디

 

로그아웃한 후 centos 계정으로 로그인한다.

[centos@localhost ~]$ pwd
/home/centos 

[centos@localhost ~]$ cd /root 

-bash: cd: /root: 허가 거부 (접근안됨)

centos 계정은 일반계정이므로 관리자 계정인 root  계정의 홈디렉토리에 접근할 수 없다.

 

2) cd .. 상위 디렉토리로 이동

3) cd 이동할 디렉토리

/home/centos 디렉토리로 이동

[centos@localhost ~]$ cd /home/centos

 

pwd(Print Work Directory)  현재 디렉토리 확인

[centos@localhost ~]$ pwd

 

다. rm (ReMove,  파일 삭제)

라. cp (CoPy, 파일 복사)

gedit test.txt

테스트를 위하여 간단하게 내용 입력 후 저장하고 닫는다.

 

test.txt 파일을 test2.txt로 복사

cp test.txt test2.txt

 

파일 이름이 test로 시작하는 모든 파일을 찾는다.

ls -la test*

 

test.txt 파일을 삭제한다.

rm test.txt

 

파일 목록을 확인한다.

ls -la test*

 

 

마. touch

크기가 0인 파일을 생성하거나 파일의 최종수정시간을 변경한다. (사용자 root)

[root@localhost ~]$ touch abc.txt

 

바. mv(MoVe) 파일 옮기기

[root@localhost ~]$ mv abc.txt /home/centos

[root@localhost ~]$ ls -la abc.txt (파일없음)

 

사. mkdir (make directory) : 디렉토리 생성

[root@localhost ~]$ mkdir abc

 

아. rmdir (remove directory) : 디렉토리 삭제

[root@localhost ~]$ rmdir abc

[root@localhost ~]$ ls -la abc (ls: cannot access abc: 그런 파일, 디렉터리가 없음)

 

자. cat (conCATenate) : 파일 내용을 표시

gedit a.txt (간단하게 내용입력하고 저장. 닫음)

gedit b.txt (간단하게 내용입력하고 저장. 닫음)

ls -la *.txt (확장자가 txt 인 파일목록 확인)

[root@localhost ~]$ cat a.txt (a.txt 파일의 내용 확인)

[root@localhost ~]$ cat b.txt

[root@localhost ~]$ cat a.txt b.txt (파일 두개 읽음)

 

차. head (위에서 몇 줄), tail (밑에서 몇 줄)

파일 내용이 길때 파일의 윗부분 5줄, 아랫부분 5줄 출력

[root@localhost ~]$ cd  head -5 anaconda-ks.cfg

[root@localhost ~]$ cd  tail -5 anaconda-ks.cfg