명령어 설명 보기
man
- Linux 기본 명령어의 설명 확인
- find 명령어의 설명이 궁금하다면?
ubuntu@$your_host_name:~$ man find
help
- 기본 제공 명령어가 아닌 경우 사용
ubuntu@$your_host_name:~$ find -help
File System
- 경로 표시 방법
- / : root 또는 dir 구분자
- ~ : 현재 user 의 home 경로
- .. : 상위 dir
- . : 현재 dir
- - : 이전 위치
- root 이전의 경로는 사용자가 접근할 수 없다
- 절대 경로의 시작점에는 항상 root 가 표시되어 있다.
pwd
- 현재 경로 확인 (print work dir)
ubuntu@$your_host_name:~$ pwd
ll, ls
- dir 및 파일 목록 확인
- ll : 자세한 목록 확인
- 숨김파일, 용량 등 자세한 정보
- 숨김파일은 파일 시작이 . 로 시작
- ls : 간단하게 확인
- -a : 숨김파일까지 확인
- -al : ll 처럼 자세한 정보 (ll 이 ls-al 의 alias)
- -R : 경로상의 모든 하위 dir 표시 (Recursive)
mkdir
- dir 생성
ubuntu@$your_host_name:~$ pwd
- -p : 하위 dir 한 번에 생성
ubuntu@$your_host_name:~$ mkdir -p dir1/dir2/dir3
=> 맨 앞에 / 를 붙여 /dir1/dir2/ 처럼 하면 root 에 생성되므로 주의!
cd
rm
- 삭제 (기본적으로는 파일 삭제)
ubuntu@$your_host_name:~$ rm sample.txt
- -r : dir 삭제
ubuntu@$your_host_name:~$ rm -r my_dir/
chmod
- 파일 권한 변경
- 파일 권한은
ls -al 을 통해 확인 가능
ubuntu@$your_host_name:~$ ls -al
>>> drwxrwr-x 3 ubuntu ubuntu 4096 Sep 10 10:57 dir1/
- 맨 앞의 파일 권한은
d/rwx/rwx/r-x 와 같이 끊어 읽는다
- d : dir 을 의미 (파일인 경우 -)
- rwx : 파일 소유자에 대한 권한 (read, write, execute)
- rwx : 소유자가 속한 그룹에 대한 권한 (read, write, execute)
- r-x : 파일 소유자가 속하지 않은 그룹에 대한 권한 (read, execute)
- chmod 를 이용해 권한을 수정하는 경우 일반적으로 숫자를 사용
- r, w, x 자리가 고정이기 때문에 binary bit 으로 표시
- ex) chmod 761
- 761 => 111/110/001
- 소유자: rwx
- 그룹: rw-
- 그룹 외: --x
File Management
touch
- 빈 파일 생성
ubuntu@$your_host_name:~$ tocuch sample.txt
cat
- 파일의 모든 내용 출력
ubuntu@$your_host_name:~$ cat sample.txt
- 빈 파일이기 때문에 아무것도 출력되지 않음
echo
- 사용자가 입력한 문자열 값을 출력
- 이를 이용해 빈 파일에 내용을 입력해보자
ubuntu@$your_host_name:~$ echo 'line1' > sample.txt
ubuntu@$your_host_name:~$ cat sample.txt
>>> line1
ubuntu@$your_host_name:~$ echo 'line2' > sample.txt
ubuntu@$your_host_name:~$ cat sample.txt
>>> line2
ubuntu@$your_host_name:~$ echo 'line3' >> sample.txt
ubuntu@$your_host_name:~$ cat sample.txt
>>> line2
>>> line3
touch 로 파일을 만들지 않아도 echo 후 > , >> 를 입력하면 파일 생성
- >, >> 는
echo 외에도 출력되는 내용을 지정 위치에 출력
man find 의 결과를 특정 파일에 삽입해보자
ubuntu@$your_host_name:~$ man find > find_manual.txt
ubuntu@$your_host_name:~$ cat find_manual.txt
>>> FIND(1) General Commands Manual
...
mv
ubuntu@$your_host_name:~$ mkdir sample2
ubuntu@$your_host_name:~$ mv sample/newfile sample2/newfile_mod
cp
ubuntu@$your_host_name:~$ cp sample2/newfile sample2/newfile_copy
파일 검색
find
- 파일 이름을 이용해 찾기
- asterisk (*) 를 이용해 패턴 지정 가능
ubuntu@$your_host_name:~$ find . -name "*in*"
./find.txt
./sample/line2.txt
./sample/find_manual.txt
./sample/line.txt
which
ubuntu@$your_host_name:~$ which find
/usr/bin/find
grep
ubuntu@$your_host_name:~$ grep -rn "[a-zA-Z]\+tion$" .
./sample/find_manual.txt:115: Enables query optimisation. The find program reorders tests to speed up execution
./sample/find_manual.txt:117: reordered relative to each other. The optimisations performed at each optimisation
./sample/find_manual.txt:202: of -newer will be dereferenced if they are symbolic links. The same consideration
./sample/find_manual.txt:225: command-line after the list of start points, just before the first test, positional option
./sample/find_manual.txt:234: -depth Process each directory's contents before the directory itself. The -delete action
./sample/find_manual.txt:850: which most Unix implementations use, but if your particular implementation
./.bashrc:113: . /usr/share/bash-completion/bash_completion
./.bashrc:115: . /etc/bash_completion
실행
sudo
- super user do 의 약자
- root 계정의 권한으로 무언가를 실행