/usr/local./teamdev2/jsg2 or teamdev2/jsg2$ pwd : (print working directory)jsg@jsg-ubuntu:~$ pwd /home/jsg
$ cd [directory] : (change directory)| 줄임 기호 | 의미 |
|---|---|
| / | root 경로 |
| ~ or 생략시 | home 경로 |
| - | 이전 경로 |
| .. | 한 단계 위 경로 |
jsg@jsg-ubuntu:~$ pwd # 현재 경로 /home/jsg jsg@jsg-ubuntu:~$ cd /tmp # /로 시작하는 절대 경로 jsg@jsg-ubuntu:/tmp$ cd ../usr # 한 단계 위로 이동 후 usr로 이동 jsg@jsg-ubuntu:/usr$ cd - # 이전 경로인 /tmp로 이동 /tmp jsg@jsg-ubuntu:/tmp$ cd ~ # 홈 디렉토리로 이동 jsg@jsg-ubuntu:~$ cd ./문서 # 홈 디렉토리에 대한 상대 경로 jsg@jsg-ubuntu:~/문서$
$ ls [option] [file_name] | 옵션 | 설명 |
|---|---|
| -a | 숨겨진 파일도 표시 |
| -l | 자세한 내용 표시 |
| -t | 시간 순 정렬 |
| -r | 역순으로 표시 |
| file access mode | |
|---|---|
![]() | ![]() |
$ mkdir [-p] file_name (make directory)jsg@jsg-ubuntu:~$ ls examples.desktop 공개 다운로드 문서 바탕화면 비디오 사진 음악 템플릿 jsg@jsg-ubuntu:~$ mkdir testdir; ls examples.desktop 공개 문서 비디오 음악 testdir 다운로드 바탕화면 사진 템플릿
$ rmdir directory라는 명령어가 있지만 디렉토리가 비어있어야 쓸 수 있으므로$ rm -rf file_name 을 더 자주 씀jsg@jsg-ubuntu:~$ rm -rf testdir jsg@jsg-ubuntu:~$ ls examples.desktop 공개 다운로드 문서 바탕화면 비디오 사진 음악 템플릿
$ echo "Hello World" > testdir/hello.txtjsg@jsg-ubuntu:~$ echo "Hello World" > testdir/hello.txt; ls testdir hello.txt
$ cat testdir/hello.txtjsg@jsg-ubuntu:~$ cat testdir/hello.txt Hello World
$ chmod XXX file_name : (changemode) 권한 변경jsg@jsg-ubuntu:~$ chmod 664 testdir; ls -l testdir ls: 'testdir/hello.txt'에 접근할 수 없습니다: 허가 거부 합계 0 -????????? ? ? ? ? ? hello.txt
# chown user_name file_name : (change owner) owner 변경root@jsg-ubuntu:/home/jsg# chown jsg2 testdir/hello.txt root@jsg-ubuntu:/home/jsg# ls -l testdir/hello.txt -rw-rw-r-- 1 jsg2 jsg 12 Dec 10 00:24 testdir/hello.txt
# chgrp group_name file_name : (change group) group 변경root@jsg-ubuntu:/home/jsg# chgrp teamdev2 testdir/hello.txt root@jsg-ubuntu:/home/jsg# ls -l testdir/hello.txt -rw-rw-r-- 1 jsg2 teamdev2 12 Dec 10 00:24 testdir/hello.txt
$ file file_name : 타입 확인, magic data를 읽음jsg@jsg-ubuntu:~$ file testdir/hello.txt testdir/hello.txt: ASCII text
$ stat file_name : 파일 메타 데이터 출력jsg@jsg-ubuntu:~$ stat testdir/hello.txt File: 'testdir/hello.txt' Size: 12 Blocks: 8 IO Block: 4096 일반 파일 Device: 801h/2049d Inode: 1175830 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1000/ jsg) Gid: ( 1000/ jsg) Access: 2020-12-10 01:38:30.838601254 +0900 Modify: 2020-12-10 00:24:52.762704113 +0900 Change: 2020-12-10 01:07:50.481252194 +0900 Birth: -
$ touch file_name : 메타 정보 갱신jsg@jsg-ubuntu:~$ stat testdir/hello.txt File: 'testdir/hello.txt' Size: 0 Blocks: 0 IO Block: 4096 일반 빈 파일 Device: 801h/2049d Inode: 1175791 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1000/ jsg) Gid: ( 1000/ jsg) Access: 2020-12-10 01:54:39.796622302 +0900 Modify: 2020-12-10 01:54:39.796622302 +0900 Change: 2020-12-10 01:54:39.796622302 +0900 Birth: - jsg@jsg-ubuntu:~$ touch testdir/hello.txt jsg@jsg-ubuntu:~$ stat testdir/hello.txt File: 'testdir/hello.txt' Size: 0 Blocks: 0 IO Block: 4096 일반 빈 파일 Device: 801h/2049d Inode: 1175791 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1000/ jsg) Gid: ( 1000/ jsg) Access: 2020-12-10 01:55:19.872828519 +0900 Modify: 2020-12-10 01:55:19.872828519 +0900 Change: 2020-12-10 01:55:19.872828519 +0900 Birth: -
$ cp file new_file : (copy)jsg@jsg-ubuntu:~$ cp -r testdir testdir2 jsg@jsg-ubuntu:~$ ls examples.desktop testdir2 다운로드 바탕화면 사진 템플릿 testdir 공개 문서 비디오 음악
$ mv file new_file : (move)jsg@jsg-ubuntu:~$ mv testdir2/hello.txt testdir/hello2.txt; ls testdir hello.txt hello2.txt
$ rm file_name (remove)$ rmdir file_name은 디렉토리가 비어있어야만 삭제되므로 잘 안씀jsg@jsg-ubuntu:~$ rm testdir/hello2.txt; ls testdir hello.txt
$ find directory [expression] : 디렉토리에서 조건에 맞는 파일 찾음| expression | 설명 |
|---|---|
| -name file_name | 이름으로 검색. "*" 사용 가능 |
| -size number | 파일 크기로 검색. +- 부호 가능 |
| -mtime time | 변경된 시간으로 검색(day) |
| -mmin time | 변경된 시간으로 검색(min) |
| -inum number | inode 번호로 검색 |
| -samefile file_name | 하드링크로 검색 |
| -maxdepth level | 최대 깊이로 검색, 여러 조건일 경우 맨 앞에 위치 |
| -mindepth level | 최소 깊이로 검색, 여러 조건일 경우 맨 앞에 위치 |
| -a (생략가능) | 조건 AND 연결 |
| -o | 조건 OR 연결 |
jsg@jsg-ubuntu:~$ mkdir ~/temp mkdir: `/home/jsg/temp' 디렉토리를 만들 수 없습니다: 파일이 있습니다 jsg@jsg-ubuntu:~$ cd temp jsg@jsg-ubuntu:~/temp$ for i in {8..21}; do dd bs=100000 count=$i \ if=/dev/zero of=./${i}00k.dat; done jsg@jsg-ubuntu:~/temp$ ls -l 합계 19852 -rw-rw-r-- 1 jsg jsg 1000000 12월 10 02:11 1000k.dat -rw-rw-r-- 1 jsg jsg 1100000 12월 10 02:11 1100k.dat -rw-rw-r-- 1 jsg jsg 1200000 12월 10 02:11 1200k.dat -rw-rw-r-- 1 jsg jsg 1300000 12월 10 02:11 1300k.dat -rw-rw-r-- 1 jsg jsg 1400000 12월 10 02:11 1400k.dat -rw-rw-r-- 1 jsg jsg 1500000 12월 10 02:11 1500k.dat -rw-rw-r-- 1 jsg jsg 1600000 12월 10 02:11 1600k.dat -rw-rw-r-- 1 jsg jsg 1700000 12월 10 02:11 1700k.dat -rw-rw-r-- 1 jsg jsg 1800000 12월 10 02:11 1800k.dat -rw-rw-r-- 1 jsg jsg 1900000 12월 10 02:11 1900k.dat -rw-rw-r-- 1 jsg jsg 2000000 12월 10 02:11 2000k.dat -rw-rw-r-- 1 jsg jsg 2100000 12월 10 02:11 2100k.dat -rw-rw-r-- 1 jsg jsg 800000 12월 10 02:11 800k.dat -rw-rw-r-- 1 jsg jsg 900000 12월 10 02:11 900k.dat
| 명령어 | 결과 |
|---|---|
| $ find . -name '[89]*k.dat' | ./900k.dat ./800k.dat |
| $ find . -name '*k.dat' -a -size 1M | ./900k.dat ./800k.dat ./1000k.dat |
| $ find . -name '*k.dat' -size +1500k -size -1800k | ./1600k.dat ./1800k.dat ./1700k.dat |
$ find ... -exec 명령어 \; : find 명령 후 작업 지시\; 인 경우 하나씩, 끝이 \+ 경우는 마지막에 한번에 실행jsg@jsg-ubuntu:~/temp$ find . -name "*k.dat" -exec rm {} \; jsg@jsg-ubuntu:~/temp$ ls -a . ..