리눅스 / 명령어 / ls / 디렉토리와 파일 목록 출력하는 명령어

ls는 list의 약어로, 디렉토리와 파일 목록을 출력하는 명령어이다.

ls 디렉토리명

  • 디렉토리에 속한 디렉토리와 파일 목록을 출력한다.
  • 숨김 파일은 나오지 않는다.
  • 디렉토리명을 생략하면 현재 디렉토리에 속한 디렉토리와 파일 목록을 출력한다.
  • 예를 들어 다음과 같이 명령하면 /var 디렉토리에 속한 디렉토리와 파일 목록을 출력한다.
# ls /var

ls -a, ls -l

  • -a 옵션을 붙이면 숨김 파일도 출력한다.
  • -l 옵션을 붙이면 소유자, 파일 크기 등 자세한 정보도 같이 출력한다.
  • -al 옵션을 붙이면 숨김 파일을 포함하여 자세한 정보를 출력한다.

제일 앞에 d가 있는 것은 디렉토리(폴더), -가 있는 것은 파일이다.

  • h 옵션을 붙이면 파일 크기를 해석하기 편하게 출력한다.

다음과 같이 명령하여 컴퓨터에 장착된 디스크와 파티션 목록을 출력할 수 있다.

# ls -l /dev/sd*
brw-rw---- 1 root disk 8, 0 Oct 31 01:58 /dev/sda
brw-rw---- 1 root disk 8, 1 Oct 31 01:58 /dev/sda1
brw-rw---- 1 root disk 8, 2 Oct 31 01:58 /dev/sda2
brw-rw---- 1 root disk 8, 16 Oct 31 01:58 /dev/sdb
brw-rw---- 1 root disk 8, 17 Oct 31 02:34 /dev/sdb1

ls *

  • *를 사용하여 특정 조건에 맞는 디렉토리와 파일만 출력할 수 있다.
  • 다음과 같이 명령하면 /etc 디렉토리에서 확장자가 conf인 파일들을 출력한다.
# ls /etc/*.conf
  • /etc 디렉토리에서 m으로 시작하고 확장자가 conf인 파일을 출력한다.
# ls /etc/m*.conf

ls --help

  • ls 명령어의 옵션을 출력한다.
# ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print C-style escapes for nongraphic characters
      --block-size=SIZE      scale sizes by SIZE before printing them; e.g.,
                               '--block-size=M' prints sizes in units of
                               1,048,576 bytes; see SIZE format below
  -B, --ignore-backups       do not list implied entries ending with ~
  -c                         with -lt: sort by, and show, ctime (time of last
                               modification of file status information);
                               with -l: show ctime and sort by name;
                               otherwise: sort by ctime, newest first
  -C                         list entries by columns
      --color[=WHEN]         colorize the output; WHEN can be 'never', 'auto',
                               or 'always' (the default); more info below
  -d, --directory            list directories themselves, not their contents
  -D, --dired                generate output designed for Emacs' dired mode
  -f                         do not sort, enable -aU, disable -ls --color
  -F, --classify             append indicator (one of */=>@|) to entries
      --file-type            likewise, except do not append '*'
      --format=WORD          across -x, commas -m, horizontal -x, long -l,
                               single-column -1, verbose -l, vertical -C
      --full-time            like -l --time-style=full-iso
  -g                         like -l, but do not list owner
      --group-directories-first
                             group directories before files;
                               can be augmented with a --sort option, but any
                               use of --sort=none (-U) disables grouping
  -G, --no-group             in a long listing, don't print group names
  -h, --human-readable       with -l, print sizes in human readable format
                               (e.g., 1K 234M 2G)
      --si                   likewise, but use powers of 1000 not 1024
  -H, --dereference-command-line
                             follow symbolic links listed on the command line
      --dereference-command-line-symlink-to-dir
                             follow each command line symbolic link
                               that points to a directory
      --hide=PATTERN         do not list implied entries matching shell PATTERN
                               (overridden by -a or -A)
      --indicator-style=WORD  append indicator with style WORD to entry names:
                               none (default), slash (-p),
                               file-type (--file-type), classify (-F)
  -i, --inode                print the index number of each file
  -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
  -k, --kibibytes            default to 1024-byte blocks for disk usage
  -l                         use a long listing format
  -L, --dereference          when showing file information for a symbolic
                               link, show information for the file the link
                               references rather than for the link itself
  -m                         fill width with a comma separated list of entries
  -n, --numeric-uid-gid      like -l, but list numeric user and group IDs
  -N, --literal              print raw entry names (don't treat e.g. control
                               characters specially)
  -o                         like -l, but do not list group information
  -p, --indicator-style=slash
                             append / indicator to directories
  -q, --hide-control-chars   print ? instead of nongraphic characters
      --show-control-chars   show nongraphic characters as-is (the default,
                               unless program is 'ls' and output is a terminal)
  -Q, --quote-name           enclose entry names in double quotes
      --quoting-style=WORD   use quoting style WORD for entry names:
                               literal, locale, shell, shell-always, c, escape
  -r, --reverse              reverse order while sorting
  -R, --recursive            list subdirectories recursively
  -s, --size                 print the allocated size of each file, in blocks
  -S                         sort by file size
      --sort=WORD            sort by WORD instead of name: none (-U), size (-S),
                               time (-t), version (-v), extension (-X)
      --time=WORD            with -l, show time as WORD instead of default
                               modification time: atime or access or use (-u)
                               ctime or status (-c); also use specified time
                               as sort key if --sort=time
      --time-style=STYLE     with -l, show times using style STYLE:
                               full-iso, long-iso, iso, locale, or +FORMAT;
                               FORMAT is interpreted like in 'date'; if FORMAT
                               is FORMAT1FORMAT2, then FORMAT1 applies
                               to non-recent files and FORMAT2 to recent files;
                               if STYLE is prefixed with 'posix-', STYLE
                               takes effect only outside the POSIX locale
  -t                         sort by modification time, newest first
  -T, --tabsize=COLS         assume tab stops at each COLS instead of 8
  -u                         with -lt: sort by, and show, access time;
                               with -l: show access time and sort by name;
                               otherwise: sort by access time
  -U                         do not sort; list entries in directory order
  -v                         natural sort of (version) numbers within text
  -w, --width=COLS           assume screen width instead of current value
  -x                         list entries by lines instead of by columns
  -X                         sort alphabetically by entry extension
  -1                         list one file per line

SELinux options:

  --lcontext                 Display security context.   Enable -l. Lines
                             will probably be too wide for most displays.
  -Z, --context              Display security context so it fits on most
                             displays.  Displays only mode, user, group,
                             security context and file name.
  --scontext                 Display only security context and file name.
      --help     display this help and exit
      --version  output version information and exit

SIZE is an integer and optional unit (example: 10M is 10*1024*1024).  Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).

Using color to distinguish file types is disabled both by default and
with --color=never.  With --color=auto, ls emits color codes only when
standard output is connected to a terminal.  The LS_COLORS environment
variable can change the settings.  Use the dircolors command to set it.

Exit status:
 0  if OK,
 1  if minor problems (e.g., cannot access subdirectory),
 2  if serious trouble (e.g., cannot access command-line argument).

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'ls invocation'
같은 카테고리의 다른 글

네트워크 / 잘 알려진 포트, 등록된 포트, 동적 포트

포트 번호는 0~65535까지 사용 가능합니다. 이를 용도에 따라 잘 알려진 포트, 등록된 포트, 동적 포트 세 가지로 분류합니다. 관리는 IANA(Internet Assigned Numbers Authority)에서 합니다.

엣지 / 아웃룩 또는 팀즈에서 링크를 클릭할 때 사이드바에 메일 내용이나 대화 나오지 않게 하는 방법

엣지 / 아웃룩 또는 팀즈에서 링크를 클릭할 때 사이드바에 메일 내용이나 대화 나오지 않게 하는 방법

기본 웹브라우저가 엣지인 상태에서 아웃룩에 있는 링크를 클릭하면, 사이드바에 메일 내용이 나온다. 팀즈에서 링크를 클릭했다면 대화 내용이 나온다. 메일이나 대화를 보기 위해 다시 아웃룩이나 팀즈로 가는 불편을 없애기 위함인 거 같은데... 사실 이게 더 불편할 수 있다. 그렇다면 설정을 변경하여 나오지 않게 할 수 있다. 사이드 창 상단에 있는 점 세 ...

워드프레스 / 댓글 핑백 허용 여부 일괄 변경하는 방법

워드프레스 / 댓글 핑백 허용 여부 일괄 변경하는 방법

댓글 핑백 허용 여부 설정 글에 댓글과 핑백을 허용할지 말지는 에서 정한다. 그러나 개별 글의 설정이 우선된다. 즉, 전체 설정에서 댓글을 허용하지 않아도, 글에서 허용하면 그 글에는 댓글을 달 수 있다. 반대로 전체 설정에서 댓글을 허용해도, 글에서 허용하지 않으면 그 글에는 댓글을 달 수 없다. 에서 댓글과 핑백 ...

버추얼박스 / 윈도우 10에서 가상 머신 만들 때 멈추는 문제 해결하는 방법

버추얼박스 / 윈도우 10에서 가상 머신 만들 때 멈추는 문제 해결하는 방법

버추얼박스로 가상 머신을 만들 때, 환경에 따라 이런 저런 문제가 발생할 수 있습니다. 이번에 생긴 문제는 아주 근본적인 문제, 가상 머신에 OS를 설치할 수 없는 것이었습니다. 윈도우 호스트에 Ubuntu 게스트를 만들려고 했는데, 아래와 같은 화면에서 멈춰서 아무 것도 할 수 없었습니다. 원인은 윈도우에 포함된 가상화 관련 기능때문이었습니다. 안드로이드 앱 개발을 위해서 ...

버추얼박스 / 가상 머신 복제하는 방법

버추얼박스 / 가상 머신 복제하는 방법

가상 머신을 여러 개 만들 경우, 서로 다른 OS로 만드는 것이라면 따로따로 만들어야 하지만, 같은 OS의 가상 머신을 여러 개 만드는 것이라면 하나를 만들고 복제하는 것이 편합니다. 버추얼박스에서 가상 머신 복제를 어떻게 하는지 알아보겠습니다. 복제하려는 가상 머신을 선택하고 마우스 우클릭합니다. 팝업 메뉴에서 를 클릭합니다. 적절히 설정 후 을 클릭합니다. 적절히 설정 후 을 클릭합니다. 적절히 ...

Ubuntu / 설치 USB 만드는 방법

ODD가 없는 컴퓨터에 OS를 설치하는 방법은 두가지입니다. 첫번째는 휴대용 ODD를 이용하는 것이고, 두번째는 USB에 설치 파일을 넣어서 이용하는 것입니다. 두번째 방법이 간편하기는 하지만 설치용 USB를 만드는 게 좀 번거롭습니다. 하지만, 우분투(Ubuntu) 설치용 USB는 몇 번의 클릭으로 쉽게 만들 수 있습니다. 우분투 다운로드 원하는 우분투 버전을 다운로드 받습니다. Universal USB Installer 다운로드 다음의 링크에서 Universal USB Installer를 다운로드 ...

Brackets / HTML, CSS 실시간 미리보기 사용하는 방법

Brackets / HTML, CSS 실시간 미리보기 사용하는 방법

Brackets의 장점 중의 하나는 실시간 미리보기입니다. HTML, CSS 등을 만들 때 유용합니다. 만약 실시간 미리보기가 안되는 상황이라면, 문서를 편집하고 저장하고 웹브라우저에서 새로 고침을 해야 하는데, Brackets의 실시간 미리보기를 이용하면 입력 또는 저장만 해도 바로 웹브라우저에 반영됩니다. 실시간 미리보기를 하려면 오른쪽에 있는 번개(?) 모양 아이콘을 클릭합니다. 실시간 미리보기를 처음 실행하는 거라면 다음과 같은 메시지가 ...

AMD CPU, 기가바이트 메인보드 사용 시 가상화 기능 활성화하는 방법

AMD CPU, 기가바이트 메인보드 사용 시 가상화 기능 활성화하는 방법

Windows에서 VirtualBox, 안드로이드 스튜디오 등을 사용하려면 가상화 기능을 활성화해야 합니다. 기가바이트 메인보드에서 AMD CPU 가상화 기능은 보통 BIOS에서 SVM Mode라고 표시됩니다.

X64와 ARM64 비교

X64와 ARM64 비교

컴퓨터와 모바일 장치의 세계에서 두 가지 주요 아키텍처가 주목받고 있습니다: x64(또는 x86-64)와 ARM64. 이 두 아키텍처는 서로 다른 방식으로 설계되고 사용됩니다. 이 포스팅에서는 x64와 ARM64 아키텍처의 차이점과 각 아키텍처의 장단점을 비교해 보겠습니다. x64 아키텍처 개요 x64는 64비트 확장판의 x86 아키텍처로, AMD가 처음 개발하여 AMD64라고 불리기도 합니다. 이후 인텔도 이 아키텍처를 채택하여 Intel 64라고 ...

IEEE 1394VT EX / 비디오 테이프를 파일로 변환할 때 필요한 카드

IEEE 1394VT EX / 비디오 테이프를 파일로 변환할 때 필요한 카드

캠코더가 있습니다. SONY Digital Handycam. 6mm 테이프를 넣어서 녹화를 하는 제품입니다. 메모리카드를 사용할 수도 있는, 한때 고급 기종이었으나, 지금은... 이것으로 찍은 테이프가 몇 개 있는데, 그동안 캠코더와 TV를 연결해서 봤었습니다. 보는 데는 문제 없지만, 보고 싶은 곳 찾기도 힘들고, 다른 사람에게 전달하기도 힘들고... 그래서 파일로 변환해보기로 했습니다. 화살표가 가리키는 곳을 이용해서 컴퓨터와 ...