리눅스 ls 옵션 d - linugseu ls obsyeon d

Updated: February 26, 2020


1. 리눅스 ls 명령어 (list)

리눅스 명령어중 ls 명령어는 디렉토리(directory)내 에 있는 내용을 확인 하는 것이다.
윈도우 cmd 에서 dir 과 같다.

~/study_linux$ ls
aa        excute.sh folder    test1.txt test2.txt


2. 옵션

-a (all)

: 숨김파일 포함하여 디렉토리의 모든 항목 표시

~/study_linux$ ls -a
.         ..        aa        excute.sh folder    test1.txt test2.txt

-l (long)

: 각 파일의 모드, 링크 수, 소유자, 그룹, 크기(바이트), 최종 수정 시간을 표시한다.
파일이 특수 파일이면 크기 필드에 주 장치 번호와 부 장치 번호가 있다.
최종 수정 시간이 6개월 이전보다 더 과거이면 시간 필드가 (월 날짜) 형식으로 표시되고, 6개월 이내이면 시간 필드가 (월 날짜 시간) 형식으로 표시

~/study_linux$ ls -l
total 24
-rw-r--r--  1 inyonghong  staff   3  2 25 21:43 aa
-rwxr-xr-x  1 inyonghong  staff   9  2 26 22:19 excute.sh
drwxr-xr-x  3 inyonghong  staff  96  2 26 21:49 folder
-rw-r--r--  1 inyonghong  staff   3  2 26 22:18 test1.txt
lrwxr-xr-x  1 inyonghong  staff  11  2 26 22:23 test2.txt -> ./test1.txt

ls -al

 ~/study_linux$ ls -al
 total 24
 drwxr-xr-x   7 inyonghong  staff   224  2 26 22:36 .
 drwx------+ 54 inyonghong  staff  1728  2 26 21:33 ..
 -rw-r--r--   1 inyonghong  staff     3  2 25 21:43 aa
 -rwxr-xr-x   1 inyonghong  staff     9  2 26 22:19 excute.sh
 drwxr-xr-x   3 inyonghong  staff    96  2 26 21:49 folder
 -rw-r--r--   1 inyonghong  staff     3  2 26 22:18 test1.txt
 lrwxr-xr-x   1 inyonghong  staff    11  2 26 22:23 test2.txt -> ./test1. txt

여기서 -al 옵션을 사용하면 숨겨진 파일목록(a)와 자세한 항목(l) 이 보여진다. 그리고 출력된 항목을 보면

파일모드링크 수소유자그룹파일 크기최종 수정 시간파일 명
drwxr-xr-x 7 inyonghong staff 224 2 26 22:36 .
drwx——+ 54 inyonghong staff 1728 2 26 21:33 ..
-rw-r–r– 1 inyonghong staff 3 2 25 21:43 aa
-rwxr-xr-x 1 inyonghong staff 9 2 26 22:19 excute.sh
drwxr-xr-x 3 inyonghong staff 96 2 26 21:49 folder
-rw-r–r– 1 inyonghong staff 3 2 26 22:18 test1.txt
lrwxr-xr-x 1 inyonghong staff 11 2 26 22:23 test2.txt -> / test1.txt

파일 모드에 맨앞에 (‘d’)는 디렉토리(directory) 이고, (‘-‘)는 일반 파일,(‘l’)은 링크 이다.
rwx/rwx/rwx는 소유자/그룹/기타 에 권한을 부여하는 것이다.

-d (directories)

: (-l과 함께 사용) 디렉토리 정보만 표시

~/study_linux$ ls -ld
drwxr-xr-x  7 inyonghong  staff  224  2 26 22:36 .

-F

: 디렉토리 (‘/’), 실행 파일 (‘*’), 링크 (‘@’), 소켓 (‘=’), 선입선출 (‘|’)

~/study_linux$ ls -F
aa         excute.sh* folder/    test1.txt  test2.txt@

~/study_linux$ ls -lF
total 24
-rw-r--r--  1 inyonghong  staff   3  2 25 21:43 aa
-rwxr-xr-x  1 inyonghong  staff   9  2 26 22:19 excute.sh*
drwxr-xr-x  3 inyonghong  staff  96  2 26 21:49 folder/
-rw-r--r--  1 inyonghong  staff   3  2 26 22:18 test1.txt
lrwxr-xr-x  1 inyonghong  staff  11  2 26 22:23 test2.txt@ -> ./test1.txt

-m

: 목록들을 콤마(,)로 구분하여 출력

~/study_linux$ ls -m
aa, excute.sh, folder, test1.txt, test2.txt

-S (size)

: 파일 크기 순으로 정렬 하여 출력

~/study_linux$ ls -S
folder    test2.txt excute.sh aa        test1.txt

 ~/study_linux$ ls -lS
total 24
drwxr-xr-x  3 inyonghong  staff  96  2 26 21:49 folder
lrwxr-xr-x  1 inyonghong  staff  11  2 26 22:23 test2.txt -> ./test1.txt
-rwxr-xr-x  1 inyonghong  staff   9  2 26 22:19 excute.sh
-rw-r--r--  1 inyonghong  staff   3  2 25 21:43 aa
-rw-r--r--  1 inyonghong  staff   3  2 26 22:18 test1.txt

-r (reverse)

: 역순으로 출력

~/study_linux$ ls -lS
total 24
drwxr-xr-x  3 inyonghong  staff  96  2 26 21:49 folder
lrwxr-xr-x  1 inyonghong  staff  11  2 26 22:23 test2.txt -> ./test1.txt
-rwxr-xr-x  1 inyonghong  staff   9  2 26 22:19 excute.sh
-rw-r--r--  1 inyonghong  staff   3  2 25 21:43 aa
-rw-r--r--  1 inyonghong  staff   3  2 26 22:18 test1.txt

~/study_linux$ ls -lSr
total 24
-rw-r--r--  1 inyonghong  staff   3  2 26 22:18 test1.txt
-rw-r--r--  1 inyonghong  staff   3  2 25 21:43 aa
-rwxr-xr-x  1 inyonghong  staff   9  2 26 22:19 excute.sh
lrwxr-xr-x  1 inyonghong  staff  11  2 26 22:23 test2.txt -> ./test1.txt
drwxr-xr-x  3 inyonghong  staff  96  2 26 21:49 folder

-R (recursive)

: 하위 디렉토리까지 출력

~/study_linux$ ls -lR
total 24
-rw-r--r--  1 inyonghong  staff   3  2 25 21:43 aa
-rwxr-xr-x  1 inyonghong  staff   9  2 26 22:19 excute.sh
drwxr-xr-x  3 inyonghong  staff  96  2 26 21:49 folder
-rw-r--r--  1 inyonghong  staff   3  2 26 22:18 test1.txt
lrwxr-xr-x  1 inyonghong  staff  11  2 26 22:23 test2.txt -> ./test1.txt

./folder:
total 8
-rw-r--r--  1 inyonghong  staff  4  2 26 21:49 f1

-h (human)

: 파일 크기를 사람이 보기 좋게 표시한다 (G, M, K, B) 단위 사용

~/study_linux$ ls -lh
total 24
-rw-r--r--  1 inyonghong  staff     3B  2 25 21:43 aa
-rwxr-xr-x  1 inyonghong  staff     9B  2 26 22:19 excute.sh
drwxr-xr-x  3 inyonghong  staff    96B  2 26 21:49 folder
-rw-r--r--  1 inyonghong  staff     3B  2 26 22:18 test1.txt
lrwxr-xr-x  1 inyonghong  staff    11B  2 26 22:23 test2.txt -> ./test1.txt

-t (time)

: 최종 수정시간을 기준으로 출력
최근에 수정한 파일이 제일 위쪽에 출력된다.

~/study_linux$ ls -lt
total 24
lrwxr-xr-x  1 inyonghong  staff  11  2 26 22:23 test2.txt -> ./test1.txt
-rwxr-xr-x  1 inyonghong  staff   9  2 26 22:19 excute.sh
-rw-r--r--  1 inyonghong  staff   3  2 26 22:18 test1.txt
drwxr-xr-x  3 inyonghong  staff  96  2 26 21:49 folder
-rw-r--r--  1 inyonghong  staff   3  2 25 21:43 aa

-T (-l과 함께)

: 날짜를 표현할때 월 일 시간(초까지) 년도 를 출력

~/study_linux$ ls -lT
total 24
-rw-r--r--  1 inyonghong  staff   3  2 25 21:43:48 2020 aa
-rwxr-xr-x  1 inyonghong  staff   9  2 26 22:19:15 2020 excute.sh
drwxr-xr-x  3 inyonghong  staff  96  2 26 21:49:40 2020 folder
-rw-r--r--  1 inyonghong  staff   3  2 26 22:18:49 2020 test1.txt
lrwxr-xr-x  1 inyonghong  staff  11  2 26 22:23:25 2020 test2.txt -> ./test1.txt

-l, -lu, -lc

: -l => 기본적으로 mtime(수정시간)을 출력 -lu => atime(접근시간)을 출력-lc => ctime(변경시간)을 출력

mtime(modification time, 수정시간) : 파일의 내용이 수정될 때 갱신
atime(access time, 접근시간) : 파일에 접근 할때 갱신 (파일을 open 할때 마다 갱신)
ctime(change time, 변경시간) : 파일의 속성, 권한, 크기 가 변경되면 갱신
stat [파일이름] 명령어로 상태정보 확인


3. 자주 사용하는 옵션 예제

ls -al

: 가장 많이 사용하는 명령어로 앞서 봤으니 예제는 생략

ls -alrt

: 숨김파일도 포함하여(a) 자세히(l) 거꾸로(r) 시간순서대로(t) 출력.
최근에 작성하거나 수정한 파일이 제일 마지막에 나타난다.

~/study_linux$ ls -alrt
total 24
-rw-r--r--   1 inyonghong  staff     3  2 25 21:43 aa
drwx------+ 54 inyonghong  staff  1728  2 26 21:33 ..
drwxr-xr-x   3 inyonghong  staff    96  2 26 21:49 folder
-rw-r--r--   1 inyonghong  staff     3  2 26 22:18 test1.txt
-rwxr-xr-x   1 inyonghong  staff     9  2 26 22:19 excute.sh
lrwxr-xr-x   1 inyonghong  staff    11  2 26 22:23 test2.txt -> ./test1.txt
drwxr-xr-x   7 inyonghong  staff   224  2 26 22:36 .

ls -alSrh

: 숨김파일 포함하여(a) 자세히(l) 파일크기 순서대로(S) 역순(r) 보기좋게 파일 단위표시하여(h) 출력

~/study_linux$ ls -alSrh
total 24
-rw-r--r--   1 inyonghong  staff     3B  2 26 22:18 test1.txt
-rw-r--r--   1 inyonghong  staff     3B  2 25 21:43 aa
-rwxr-xr-x   1 inyonghong  staff     9B  2 26 22:19 excute.sh
lrwxr-xr-x   1 inyonghong  staff    11B  2 26 22:23 test2.txt -> ./test1.txt
drwxr-xr-x   3 inyonghong  staff    96B  2 26 21:49 folder
drwxr-xr-x   7 inyonghong  staff   224B  2 26 22:36 .
drwx------+ 54 inyonghong  staff   1.7K  2 26 21:33 ..