리눅스 명령어 ls

김규연·2023년 7월 14일
0

linux

목록 보기
6/11

⚙️ 리눅스 명령 구조

형식 -> 명령 [옵션][인자]

  • 명령 : 사용자가 컴퓨터 운영체제나 응용프로그램에게 어떤 서비스를 수행하도록 요구하는 것
  • 옵션 : 옵션을 사용하여 명령의 세부 기능을 선택할 수 있다. 리눅스의 기능을 풍부하게 하는 중요한 특징. "-"기호로 시작하며 영문 소문자나 대문자로 구성. 명령에 따라 어떤 옵션이 있고 그 기능이 무엇인지는 해당 명령의 사용법을 참조
  • 인자 : 명령으로 전달되는 값으로 주로 파일명이나 디렉터리명

🧐 목록 출력 명령어 ls

  • ls [디렉토리]
    ls 명령어는 list의 줄임말로 현재 디렉토리의 파일 목록을 확인하는 명령어이다. 리눅스의 기본 명령어 중 제일 많이 사용하는 명령어로써 자주 사용하는 옵션이나 그 외 옵션들의 사용법을 숙지하면 업무 및 개발에 유용하게 쓰일 수 있다. 또한 다양한 옵션을 사용하여 디렉토리 및 파일의 권한과 소유자의 데이터를 확인할 수 있고 원하는 형식으로 출력 형식을 변경할 수 있다.
  • 디렉토리를 지정하여 파일 목록을 출력할 수 있다.
  • 옵션을 사용하지 않으면 숨김 파일은 나오지 않는다.
  • 디렉토리명을 생략하면 현재 위치한 디렉토리의 파일 목록을 출력한다.

📌 ls 명령어 옵션

옴션설명
-aall의 줄임말로 숨겨진 파일이나 디렉토리를 포함 모든 파일 형식을 출력(숨김처리 파일에는 앞에 .이 붙음)
-A. 와 .. 을 제회하고 목록을 출력
-b알파벳 순으로 목록을 출력
-B~로 끝나는 백업파일을 제외하고 목록을 출력
-c-l 옵션을 같이 사용. 마지막으로 변경된 시간을 목록에 출력
-C파일이나 디렉토리를 열로 목록을 출력
-d지정경로에 있는 최상위 디렉토리의 목록만 출력(*/ 디렉토리만 출력)
-Demacs를 위한 출력행태를 생성
-f정렬하지 않고 컬러 옵션을 해제하여 출력
-F파일의 종류를 기호로 구분하여 출력(디렉토리 /, 소켓 =, 실행가능파일 *, 링크 @)
-g사용자 권한을 출력
-G-l 과 같이 사용시 그룹권한을 출력하지 않음
-hhuman의 줄임말로 K(킬로바이트), M(메가바이트), G(기가바이트) 단위를 사용하여 파일 크기를 사람이 보기 좋게 표시
-H심볼릭 링크의 실제 참조하는 목록을 출력
-i파일의 인덱스 값을 출력(인덱스:파일 시스템과 관련한 중요한 자료구조 중 하나로서 inode라고 부름)
-I(대문자 i)지정한 파일 및 디렉토리를 제외하고 출력
-k용량을 킬로바이트로 출력
-llong의 줄임말로 자세한 내용을 출력. 내용 > 권한, 파일 수, 소유자, 그룹, 파일크기, 수정일자, 파일이름
-lumtime(수정시간)과 atime(접근시간)을 출력 (default는 수정시간)
-lcmtime(수정시간)과 ctime(변경시간)을 출력 (default는 수정시간)
-L심볼릭 링크의 정보를 출력할 때 원본 파일의 정보를 출력
-m파일의 출력 형식이 디렉토리 및 파일을 쉼표로 구분하여 출력
-n사용자와 그룹권한을 UDI와 GID로 표시
-p디렉토리에 /을 추가
-q그래픽이 아닌 문자 대신에 ?를 출력
-Q파일, 디렉토리를 쌍따옴표 안에 출력
-rreverse의 줄임말로 반대로 출력 (default는 알파벳 순서)
-R하위 디렉토리까지 출력
-s각 파일의 할단된 크기를 블록으로 출력
-S파일크기 순으로 정렬하여 출력
-t파일이 수정된 시간 기준으로 정렬 출력
-Ttab 사이즈 별로 출력
-u-lt 같이 사용시 생성 시간 기준으로 출력하고 -l과 사용시 atime(생성시간) 순으로 정렬 출력
-U디스크의 저장된 순서대로 파일 나열
-wwidth 길이를 설정하여 출력
-x상세 출력되는 리스트를 열이 아닌 하나의 라인으로 출력
-X확장자의 알파벳순으로 정렬하여 출력
-ZSELinux 보안 모듈을 출력

📚 실습 및 활용

📝 ls -a

all 의 줄임말로 모든 파일(숨김 파일 및 디렉토리 포함) 형식을 출력한다.

[root@localhost ~]# ls -a
.              .bashrc          bro        hi          text.txt
..             .cshrc           file.txt   name.txt    welcome.txt
.bash_logout   .tcshrc          hello      newfile     world
.bash_profile  anaconda-ks.cfg  hello.txt  number.txt

숨기파일은 앞에 .이 붙는다.

📝 ls -A

지정된 디렉토리의 현재 디렉토리(.)와 상위 디렉토리(..)을 제외한 모든 파일 및 디렉토리를 출력한다.

[root@localhost ~]# ls -A
.bash_logout   .cshrc           bro       hello.txt  newfile     welcome.txt
.bash_profile  .tcshrc          file.txt  hi         number.txt  world
.bashrc        anaconda-ks.cfg  hello     name.txt   text.txt

📝 ls -h

K (킬로바이트), M (메가바이트), G (기가바이트) 형태로 사용자가 보기좋게 출력한다. -l 옵션과 함께 사용한다.

[root@localhost ~]# ls -lh
합계 40K
-rw-------. 1 root root 1.2K  7월 12 16:23 anaconda-ks.cfg
-rw-r--r--. 1 root root    4  7월 13 13:14 bro
-rw-r--r--. 1 root root   12  7월 13 13:17 file.txt
-rw-r--r--. 1 root root    0  7월 13 11:09 hello
-rw-r--r--. 1 root root   17  7월 13 13:41 hello.txt
-rw-r--r--. 1 root root    4  7월 13 12:01 hi
-rw-r--r--. 1 root root   32  7월 13 13:41 name.txt
-rw-r--r--. 1 root root   27  7월 13 13:23 newfile
-rw-r--r--. 1 root root   61  7월 13 13:53 number.txt
-rw-r--r--. 1 root root   27  7월 13 13:25 text.txt
-rw-r--r--. 1 root root   48  7월 13 13:31 welcome.txt
-rw-r--r--. 1 root root    0  7월 13 11:09 world

📝 ls -l

자세한 내용을 출력한다. 여기서 내용은 권한, 파일 수, 소유자, 그룹, 파일크기, 수정일자, 파일이름을 의미한다.

[root@localhost ~]# ls -l
합계 40
-rw-------. 1 root root 1214  7월 12 16:23 anaconda-ks.cfg
-rw-r--r--. 1 root root    4  7월 13 13:14 bro
-rw-r--r--. 1 root root   12  7월 13 13:17 file.txt
-rw-r--r--. 1 root root    0  7월 13 11:09 hello
-rw-r--r--. 1 root root   17  7월 13 13:41 hello.txt
-rw-r--r--. 1 root root    4  7월 13 12:01 hi
-rw-r--r--. 1 root root   32  7월 13 13:41 name.txt
-rw-r--r--. 1 root root   27  7월 13 13:23 newfile
-rw-r--r--. 1 root root   61  7월 13 13:53 number.txt
-rw-r--r--. 1 root root   27  7월 13 13:25 text.txt
-rw-r--r--. 1 root root   48  7월 13 13:31 welcome.txt
-rw-r--r--. 1 root root    0  7월 13 11:09 world

📝 -ls -r

reverse의 줄임말로 default가 알파벳 순으로 출력한다면 알파벳 역순으로 출력한다.

[root@localhost ~]# ls -r
world        text.txt    newfile   hi         hello     bro
welcome.txt  number.txt  name.txt  hello.txt  file.txt  anaconda-ks.cfg
[root@localhost ~]# ls -lr
합계 40
-rw-r--r--. 1 root root    0  7월 13 11:09 world
-rw-r--r--. 1 root root   48  7월 13 13:31 welcome.txt
-rw-r--r--. 1 root root   27  7월 13 13:25 text.txt
-rw-r--r--. 1 root root   61  7월 13 13:53 number.txt
-rw-r--r--. 1 root root   27  7월 13 13:23 newfile
-rw-r--r--. 1 root root   32  7월 13 13:41 name.txt
-rw-r--r--. 1 root root    4  7월 13 12:01 hi
-rw-r--r--. 1 root root   17  7월 13 13:41 hello.txt
-rw-r--r--. 1 root root    0  7월 13 11:09 hello
-rw-r--r--. 1 root root   12  7월 13 13:17 file.txt
-rw-r--r--. 1 root root    4  7월 13 13:14 bro
-rw-------. 1 root root 1214  7월 12 16:23 anaconda-ks.cfg
[root@localhost ~]# ls -l
합계 40
-rw-------. 1 root root 1214  7월 12 16:23 anaconda-ks.cfg
-rw-r--r--. 1 root root    4  7월 13 13:14 bro
-rw-r--r--. 1 root root   12  7월 13 13:17 file.txt
-rw-r--r--. 1 root root    0  7월 13 11:09 hello
-rw-r--r--. 1 root root   17  7월 13 13:41 hello.txt
-rw-r--r--. 1 root root    4  7월 13 12:01 hi
-rw-r--r--. 1 root root   32  7월 13 13:41 name.txt
-rw-r--r--. 1 root root   27  7월 13 13:23 newfile
-rw-r--r--. 1 root root   61  7월 13 13:53 number.txt
-rw-r--r--. 1 root root   27  7월 13 13:25 text.txt
-rw-r--r--. 1 root root   48  7월 13 13:31 welcome.txt
-rw-r--r--. 1 root root    0  7월 13 11:09 world

📝 ls -S (대문자)

파일의 크기별로 정렬하여 출력한다.

[root@localhost ~]# ls -S
anaconda-ks.cfg  welcome.txt  newfile   hello.txt  bro  hello
number.txt       name.txt     text.txt  file.txt   hi   world
[root@localhost ~]# ls -lS
합계 40
-rw-------. 1 root root 1214  7월 12 16:23 anaconda-ks.cfg
-rw-r--r--. 1 root root   61  7월 13 13:53 number.txt
-rw-r--r--. 1 root root   48  7월 13 13:31 welcome.txt
-rw-r--r--. 1 root root   32  7월 13 13:41 name.txt
-rw-r--r--. 1 root root   27  7월 13 13:23 newfile
-rw-r--r--. 1 root root   27  7월 13 13:25 text.txt
-rw-r--r--. 1 root root   17  7월 13 13:41 hello.txt
-rw-r--r--. 1 root root   12  7월 13 13:17 file.txt
-rw-r--r--. 1 root root    4  7월 13 13:14 bro
-rw-r--r--. 1 root root    4  7월 13 12:01 hi
-rw-r--r--. 1 root root    0  7월 13 11:09 hello
-rw-r--r--. 1 root root    0  7월 13 11:09 world

📝 ls -t

최근 수정된 파일을 맨 위로 정렬시켜 출력한다.

[root@localhost ~]# ls -t
number.txt  hello.txt    text.txt  file.txt  hi     world
name.txt    welcome.txt  newfile   bro       hello  anaconda-ks.cfg
[root@localhost ~]# ls -lt
합계 40
-rw-r--r--. 1 root root   61  7월 13 13:53 number.txt
-rw-r--r--. 1 root root   32  7월 13 13:41 name.txt
-rw-r--r--. 1 root root   17  7월 13 13:41 hello.txt
-rw-r--r--. 1 root root   48  7월 13 13:31 welcome.txt
-rw-r--r--. 1 root root   27  7월 13 13:25 text.txt
-rw-r--r--. 1 root root   27  7월 13 13:23 newfile
-rw-r--r--. 1 root root   12  7월 13 13:17 file.txt
-rw-r--r--. 1 root root    4  7월 13 13:14 bro
-rw-r--r--. 1 root root    4  7월 13 12:01 hi
-rw-r--r--. 1 root root    0  7월 13 11:09 hello
-rw-r--r--. 1 root root    0  7월 13 11:09 world
-rw-------. 1 root root 1214  7월 12 16:23 anaconda-ks.cfg

📝 ls -b

알파벳 순으로 파일 및 디렉토리를 출력한다.

[root@localhost ~]# ls -b
anaconda-ks.cfg  file.txt  hello.txt  name.txt  number.txt  welcome.txt
bro              hello     hi         newfile   text.txt    world
[root@localhost ~]# ls -lb
합계 40
-rw-------. 1 root root 1214  7월 12 16:23 anaconda-ks.cfg
-rw-r--r--. 1 root root    4  7월 13 13:14 bro
-rw-r--r--. 1 root root   12  7월 13 13:17 file.txt
-rw-r--r--. 1 root root    0  7월 13 11:09 hello
-rw-r--r--. 1 root root   17  7월 13 13:41 hello.txt
-rw-r--r--. 1 root root    4  7월 13 12:01 hi
-rw-r--r--. 1 root root   32  7월 13 13:41 name.txt
-rw-r--r--. 1 root root   27  7월 13 13:23 newfile
-rw-r--r--. 1 root root   61  7월 13 13:53 number.txt
-rw-r--r--. 1 root root   27  7월 13 13:25 text.txt
-rw-r--r--. 1 root root   48  7월 13 13:31 welcome.txt
-rw-r--r--. 1 root root    0  7월 13 11:09 world

📝 ls -i

각 파일의 인덱스 값을 첫번째 열에 출력한다. (인덱스 : 파일 시스템과 관련한 중요한 자료구조)

[root@localhost ~]# ls -i
33574979 anaconda-ks.cfg  34119682 hello.txt  34119684 number.txt
34119670 bro              33574989 hi         33576660 text.txt
34119679 file.txt         34119683 name.txt   34119681 welcome.txt
33574983 hello            34119680 newfile    33574986 world
[root@localhost ~]# ls -li
합계 40
33574979 -rw-------. 1 root root 1214  7월 12 16:23 anaconda-ks.cfg
34119670 -rw-r--r--. 1 root root    4  7월 13 13:14 bro
34119679 -rw-r--r--. 1 root root   12  7월 13 13:17 file.txt
33574983 -rw-r--r--. 1 root root    0  7월 13 11:09 hello
34119682 -rw-r--r--. 1 root root   17  7월 13 13:41 hello.txt
33574989 -rw-r--r--. 1 root root    4  7월 13 12:01 hi
34119683 -rw-r--r--. 1 root root   32  7월 13 13:41 name.txt
34119680 -rw-r--r--. 1 root root   27  7월 13 13:23 newfile
34119684 -rw-r--r--. 1 root root   61  7월 13 13:53 number.txt
33576660 -rw-r--r--. 1 root root   27  7월 13 13:25 text.txt
34119681 -rw-r--r--. 1 root root   48  7월 13 13:31 welcome.txt
33574986 -rw-r--r--. 1 root root    0  7월 13 11:09 world

📝 ls -I [파일 및 디렉토리] (대문자 i)

지정한 파일 및 디렉토리를 제외하고 출력한다.

[root@localhost ~]# ls -S
anaconda-ks.cfg  welcome.txt  newfile   hello.txt  bro  hello
number.txt       name.txt     text.txt  file.txt   hi   world
[root@localhost ~]# ls -I hi
anaconda-ks.cfg  file.txt  hello.txt  newfile     text.txt     world
bro              hello     name.txt   number.txt  welcome.txt

📝 ls -m

디렉토리 및 파일을 쉼표로 구분하여 출력한다.

[root@localhost ~]# ls -m
anaconda-ks.cfg, bro, file.txt, hello, hello.txt, hi, name.txt, newfile,
number.txt, text.txt, welcome.txt, world

참고한 사이트

profile
오늘도 뚠뚠 개미 개발자

0개의 댓글