05_Simple Coding - Linux - 파일_컨트롤

강태경·2024년 2월 18일

Linux

목록 보기
6/9

📃 요약

리눅스는 윈도우와 달리 주로 키보드를 이용해서 명령어를 타이핑해서 여러가지 기능들을 실행함
예를 들어 대표적으로 폴더 만들기, 파일만들기 명령어 등이 있음

요소 기술 :

- Basic : 리눅스

📃 기술 구현

스펙 :

- docker desktop
- linux

📃 Linux 란

- 리눅스 : 운영체제 (윈도우 같은 것, OS)
- 컴퓨터의 하드웨어(cpu , 메모리 , 프린터 , 키보드 등) 관리하는 s/w
- 무료 리눅스 / 유료 리눅스가 있음
    1) 무료 리눅스 : 우분투, 센토스 등
    2) 유료 리눅스 : 레드헷 등

Linux 사용 목적

- 업무용 OS(운영체제) : 안정성 높음
- 안정성 : 업무용 S/W 는 1년 무중단으로 프로그램이 실행되어야 함
- 윈도우는 1년 무중단으로 실행시 리눅스보다 컴퓨터가 꺼지거나 에러가 발생할 위험이 높음

Linux 특징

- CLI(Command Line Interface) : 명령어를 입력해서 실행하는 프로그램
- GUI(Graphic User Interface) : 마우스를 이용해 실행하는 프로그램(한글, 워드 등)

리눅스의 파일/디렉토리 알기

1) 리눅스의 모든 하드웨어 장치(프린터,디스크 등)는 모두 파일로 이루어져 있음
2) 디렉토리 == 폴더
3) 디렉토리 구조
(1) PATH(경로) : /(슬래쉬) 를 사용해서 디렉토리 경로를 표시함
    예) /usr/bin/perl -> /usr 디렉토리 안에 /bin 디렉토리 안에 perl 파일(vs 윈도우즈( \(역슬래쉬)))
(2) 리눅스의 최상위 경로 : / => root(뿌리) 경로, 1개만 있음
(3) 리눅스 설치시 여러 의미 있는 디렉토리가 있음
(4) /bin : 명령어 실행 파일이 존재하는 디렉토리
           중요도가 높은 명령어 들이 있음
    /etc : 리눅스에서 실행되는 다양한 환경 설정 파일이 존재 (패스워드, 그룹정보 등)
   /home : 사용자별로 할당(배정)되는 작업 디렉토리
   /sbin : 관리자용 명령어들이 포함된 디렉토리(서버끄기/켜기 등)
   /tmp  : 프로그램 실행시 임시 파일이 필요한데 그 파일이 들어 있는 디렉토리(주기적으로 리눅스가 삭제함)
   /usr  : 설치한 프로그램이 들어 있는 디렉토리(oracle, 웹서버 프로그램 등)
   /var  : 변화하는(Variable) 파일/데이터를 저장하기 위한 디렉토리 (메일, 로그 등)

1) 홈디렉토리에서(/home/oracle) work 디렉토리를 만드세요

[] : 안에 생략 될 수 있음
사용법) mkdir [옵션] 디렉토리명
oracle@731130ee71d4:~$ pwd
/home/oracle
oracle@731130ee71d4:~$ mkdir work
oracle@731130ee71d4:~$ ls
report  work
oracle@731130ee71d4:~$
자식 디렉토리까지 만들기 : 옵션 -p
사용법) mkdir -p 경로(자식디렉토리 포함)
oracle@731130ee71d4:~$ mkdir -p report/2021/05
oracle@731130ee71d4:~$ cd report/2021/05
oracle@731130ee71d4:~/report/2021/05$ pwd
/home/oracle/report/2021/05

2) 빈 파일 만들기

사용법) touch 생성할파일명1 생성할파일명2 ...
work 디렉토리로 이동해서 newfile 빈 파일을 만들어 주세요
oracle@731130ee71d4:~$ cd work
oracle@731130ee71d4:~/work$ pwd
oracle@731130ee71d4:~/work$ touch newfile
oracle@731130ee71d4:~/work$ ls
newfile

3) 파일 삭제하기

사용법) rm 파일명1 파일명2 ...
work 디렉토리로 이동해서 newfile 삭제해 보세요
oracle@731130ee71d4:~/work$ ls
newfile
oracle@731130ee71d4:~/work$ rm newfile
oracle@731130ee71d4:~/work$ ls

4) touch 명령어를 이용해서 file1, file2, file3 을

work 디렉토리에 만드세요
oracle@731130ee71d4:~/work$ touch file1 file2 file3
oracle@731130ee71d4:~/work$ ls
file1  file2  file3

5) file1, file2, file3 을 삭제하세요

oracle@731130ee71d4:~/work$ rm file1 file2 file3
oracle@731130ee71d4:~/work$ ls
oracle@731130ee71d4:~/work$

6) 디렉토리 삭제하기 :

사용법) rmdir 디렉토리명
work 디렉토리에서 빈 디렉토리 dir1 만들고(mkdir) rmdir 을 이용해서 dir1 을 삭제해 보세요
oracle@731130ee71d4:~/work$ mkdir dir1
oracle@731130ee71d4:~/work$ ls
dir1
oracle@731130ee71d4:~/work$ rmdir dir1
oracle@731130ee71d4:~/work$ ls
oracle@731130ee71d4:~/work$

7) dir1 빈 디렉토리 삭제하기 ? rmdir (X)

oracle@731130ee71d4:~/work$ rmdir dir1
rmdir: failed to remove 'dir1': Directory not empty
oracle@731130ee71d4:~/work$
1st 방법) 일단 dir1 으로 들어가서 rm 파일명 으로 모두 삭제한후 , 다시 나와서 rmdir 빈디렉토리명 삭제
2nd 방법) rm -rf 디렉토리명, (사용시 주의)

8) 파일 내용 출력하기

cat [옵션] 인자(매개변수)
oracle@731130ee71d4:~/work$ touch newfile
oracle@731130ee71d4:~/work$ ls
newfile
빈 파일은 화면에 출력안됨
oracle@731130ee71d4:~/work$ cat newfile
/etc/hostname : 컴퓨터이름 있는 파일(환경 파일)
oracle@731130ee71d4:~/work$ cat /etc/hostname
731130ee71d4
cat 파일명 : 파일을 읽어서 화면에 출력
cat
Hello
Hello
ctrl + d
oracle@731130ee71d4:~$ cat
Hello
Hello
(ctrl + d)
oracle@731130ee71d4:~$

9) 파일의 내용이 많은 파일을 스크롤해서 표시하기

대상파일 : .bashrc (개인 환경설정 파일)
less 파일명 : 페이지 단위로 읽는 명령어
다음 파일을 읽어 주세요
less .bashrc
옵션 :
space 키 : 한 화면 아래로 스크롤( 다음 페이지)
b : 이전 화면으로 스크롤( 이전 페이지)
q : less 명령어 종료
/찾을문자열 : 찾을문자열을 아래 방향으로 검색
?찾을문자열 : 찾을문자열을 윗 방향으로 검색
n : 다음 검색 결과로 이동
N : 이전 검색 결과로 이동
oracle@731130ee71d4:~$ less .bashrc

10) 파일과 디렉토리 복사하기

사용법) cp [옵션] 복사할파일 복사될경로(새로운파일명)
work 에서 새 파일 file1 만들어(touch) file2 로 복사하세요
파일 복사하기
사용법) cp 복사할파일 새로운파일명
oracle@731130ee71d4:~/work$ pwd
/home/oracle/work
oracle@731130ee71d4:~/work$ touch file1
oracle@731130ee71d4:~/work$ ls
file1  newfile
oracle@731130ee71d4:~/work$ cp file1 file2
oracle@731130ee71d4:~/work$ ls
file1  file2  newfile
oracle@731130ee71d4:~/work$
디렉토리 안에 복사하기(같은 이름으로)
사용법) cp 복사할파일 경로
연습) work 에서 dir1 디렉토리를 만들고 file1 을 dir1 안에 같은이름으로 복사하세요
oracle@731130ee71d4:~/work$ mkdir dir1
oracle@731130ee71d4:~/work$ ls
dir1  file1  file2  newfile
oracle@731130ee71d4:~/work$ cp file1 dir1
oracle@731130ee71d4:~/work$ ls dir1
file1
oracle@731130ee71d4:~/work$
profile
IT FullStack 강사

0개의 댓글