리눅스 / 명령어 / 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'
같은 카테고리의 다른 글
CentOS 7 / 설치하기

CentOS 7 / 설치하기

CentOS ISO 다운로드 CentOS ISO 파일은 DVD ISO, Everything ISO, Minimal ISO, NetInstall ISO 등 여러 가지가 있습니다. 이 중에서 가장 파일 크기가 작은 NetInstall ISO 파일로 설치하겠습니다. NetInstall ISO는 설치에 필요한 최소한의 파일만 포함하고 있고, 추가 소프트웨어는 다운로드 받아 설치합니다. CentOS 7의 NetInstall ISO 파일은 다음 링크에서 다운로드를 받을 수 있습니다. http://mirror.navercorp.com/centos/7/isos/x86_64/ 파일 이름은 CentOS-7-x86_64-NetInstall-xxxx.iso입니다. CD로 부팅 ISO 파일을 CD에 ...

CentOS 7 / ntsysv로 부팅할 때 서비스 자동으로 시작하게 하기

CentOS 7 / ntsysv로 부팅할 때 서비스 자동으로 시작하게 하기

서비스 관리는 보통 systemctl 명령어로 합니다. systemctl 명령어의 enable을 이용하면 시스템이 부팅할 때 서비스가 자동으로 시작하게 할 수 있습니다. 예를 들어 systemctl enable httpd.service 는 서버가 부팅할 때 httpd 서비스를 자동으로 시작합니다. 만약 이러한 서비스 관리를 명령어로 하는 불편하다면 ntsysv를 사용해보세요. TUI로 자동으로 시작하는 서비스를 관리할 수 있습니다. 다음과 같이 명령하여 ntsysv 패키지를 설치합니다. yum install ntsysv 다음과 같이 ...

리눅스 / 명령어 / rm / 파일 또는 디렉토리 삭제하는 명령어

rm은 remove의 약자로, 파일 또는 디렉토리를 삭제하는 명령어이다. 파일 삭제하기 abc.txt 파일을 삭제한다. 삭제할 건지 다시 묻는다. y 또는 yes를 입력하면 삭제한다. # rm abc.txt 확장자가 txt인 모든 파일을 삭제한다. 각 파일에 대해서 삭제할 건지 묻는다. # rm *.txt 현재 디렉토리에 있는 모든 파일을 삭제한다. 각 파일에 대해서 삭제할 건지 묻고, 디렉토리가 있다면 삭제할 수 없다는 ...

Ubuntu Server / Let’s Encrypt 무료 SSL 인증서 발급 받기

Ubuntu Server에서 Apache Web Server를 사용하는 경우 Let’s Encrypt 인증서 발급 받는 방법이다. Apache용 Certbot 설치 Ubuntu Server 20.04, Ubuntu Server 22.04 snap install core snap refresh core snap install --classic certbot ln -s /snap/bin/certbot /usr/bin/certbot Ubuntu Server 18.04 apt install software-properties-common add-apt-repository universe add-apt-repository ppa:certbot/certbot apt update apt upgrade apt install certbot python3-certbot-apache Ubuntu Server 16.04 add-apt-repository ppa:certbot/certbot apt update apt upgrade apt install python-certbot-apache 인증서 발급 abc.com 인증서 ...

리눅스 / 명령어 / which, whereis, locate / 명령어 위치 찾기

명령어의 위치를 찾을 때 사용할 수 있는 명령어에는 which, whereis, locate가 있다. 명령어의 위치만 찾을 때는 which를 사용하고, 관련된 파일들의 위치까지 찾을 때는 whereis나 locate를 사용한다. which 명령어로 find 명령어를 찾는다. # which find /usr/bin/find whereis 명령어로 find 명령어를 찾는다. # whereis find find: /usr/bin/find /usr/share/man/man1/find.1.gz locate 명령어로 find 명령어를 찾는다. # locate find /usr/bin/find /usr/bin/find2perl /usr/bin/findmnt /usr/bin/nl-link-ifindex2name /usr/bin/nl-link-name2ifindex /usr/bin/oldfind /usr/lib64/python2.7/modulefinder.py /usr/lib64/python2.7/modulefinder.pyc /usr/lib64/python2.7/modulefinder.pyo /usr/sbin/btrfs-find-root /usr/sbin/findfs /usr/share/bash-completion/completions/findmnt /usr/share/doc/findutils-4.5.11 /usr/share/doc/findutils-4.5.11/AUTHORS /usr/share/doc/findutils-4.5.11/COPYING /usr/share/doc/findutils-4.5.11/ChangeLog /usr/share/doc/findutils-4.5.11/NEWS /usr/share/doc/findutils-4.5.11/README /usr/share/doc/findutils-4.5.11/THANKS /usr/share/doc/findutils-4.5.11/TODO /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_find.py /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_stop_find.py /usr/share/info/find-maint.info.gz /usr/share/info/find.info.gz /usr/share/locale/be/LC_MESSAGES/findutils.mo /usr/share/locale/bg/LC_MESSAGES/findutils.mo /usr/share/locale/ca/LC_MESSAGES/findutils.mo /usr/share/locale/cs/LC_MESSAGES/findutils.mo /usr/share/locale/da/LC_MESSAGES/findutils.mo /usr/share/locale/de/LC_MESSAGES/findutils.mo /usr/share/locale/el/LC_MESSAGES/findutils.mo /usr/share/locale/eo/LC_MESSAGES/findutils.mo /usr/share/locale/es/LC_MESSAGES/findutils.mo /usr/share/locale/et/LC_MESSAGES/findutils.mo /usr/share/locale/fi/LC_MESSAGES/findutils.mo /usr/share/locale/fr/LC_MESSAGES/findutils.mo /usr/share/locale/ga/LC_MESSAGES/findutils.mo /usr/share/locale/gl/LC_MESSAGES/findutils.mo /usr/share/locale/hr/LC_MESSAGES/findutils.mo /usr/share/locale/hu/LC_MESSAGES/findutils.mo /usr/share/locale/id/LC_MESSAGES/findutils.mo /usr/share/locale/it/LC_MESSAGES/findutils.mo /usr/share/locale/ja/LC_MESSAGES/findutils.mo /usr/share/locale/ko/LC_MESSAGES/findutils.mo /usr/share/locale/lg/LC_MESSAGES/findutils.mo /usr/share/locale/lt/LC_MESSAGES/findutils.mo /usr/share/locale/ms/LC_MESSAGES/findutils.mo /usr/share/locale/nl/LC_MESSAGES/findutils.mo /usr/share/locale/pl/LC_MESSAGES/findutils.mo /usr/share/locale/pt/LC_MESSAGES/findutils.mo /usr/share/locale/pt_BR/LC_MESSAGES/findutils.mo /usr/share/locale/ro/LC_MESSAGES/findutils.mo /usr/share/locale/ru/LC_MESSAGES/findutils.mo /usr/share/locale/rw/LC_MESSAGES/findutils.mo /usr/share/locale/sk/LC_MESSAGES/findutils.mo /usr/share/locale/sl/LC_MESSAGES/findutils.mo /usr/share/locale/sr/LC_MESSAGES/findutils.mo /usr/share/locale/sv/LC_MESSAGES/findutils.mo /usr/share/locale/tr/LC_MESSAGES/findutils.mo /usr/share/locale/uk/LC_MESSAGES/findutils.mo /usr/share/locale/vi/LC_MESSAGES/findutils.mo /usr/share/locale/zh_CN/LC_MESSAGES/findutils.mo /usr/share/locale/zh_TW/LC_MESSAGES/findutils.mo /usr/share/man/man1/find.1.gz /usr/share/man/man1/find2perl.1.gz /usr/share/man/man1/oldfind.1.gz /usr/share/man/man8/btrfs-find-root.8.gz /usr/share/man/man8/findfs.8.gz /usr/share/man/man8/findmnt.8.gz locate 명령어는 -n 옵션으로 출력 ...

CentOS 7 / 다운로드 하는 방법

CentOS 7 / 다운로드 하는 방법

CentOS는 세계 곳곳의 서버에서 다운로드할 수 있습니다. 다운로드하려는 곳에서 가까운 곳에 있고 회선이 좋은 서버에서 다운로드 받아야 빠르게 다운로드 할 수 있습니다. 다행이 CentOS는 가까운 서버를 알려줘서 다운로드에 소요되는 시간을 줄일 수 있습니다. CentOS 공식 다운로드 페이지로 갑니다. 다운로드 하고 싶은 ISO를 클릭합니다. 카이스트, 카카오, 네이버 등 국내 다운로드 주소를 먼저 보여줍니다. 마음에 드는 ...

Ubuntu 22.04 Server / ZIP 압축 파일 푸는 방법

ZIP 파일을 압축 해제하기 위해서는 unzip 패키지가 필요하다. # apt install unzip xxx.zip 파일을 압축 해제하려면 다음과 같이 명령한다. # unzip xxx.zip 다음과 같이 명령하여 도움말을 볼 수 있다. # unzip -h 결과는 다음과 같다. UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP. Usage: unzip Default ...

Ubuntu 22.04 Server / 원격 데스크톱으로 연결하는 방법

Ubuntu 22.04 Server / 원격 데스크톱으로 연결하는 방법

GUI 설치 우분투에 GUI를 설치한다. # apt install ubuntu-desktop-minimal xrdp 설치 xrdp를 설치한다. # apt install xrdp 방화벽 설정 원격 데스크톱은 3389 포트를 사용하므로, 방화벽을 사용하고 있다면 포트를 열어 준다. ufw allow 3389/tcp 원격 데스크톱 연결 원격 데스크톱으로 접속한다. 아래와 같은 창이 뜨는데, 를 클릭한다. 계정 정보를 입력하고 를 클릭하면... 원격지에서 GUI로 우분투를 즐길 수 있다.

Rocky Linux 9 / 설치

Rocky Linux 9 / 설치

다운로드 아래 링크에서 ISO 파일을 다운로드한다. https://rockylinux.org/download Boot, Minimal, DVD 세 가지가 있는데, 다음과 같이 설명되어 있다. Boot Used to install the operating system from another source (such as a HTTP repository of the binary files). Can also be used to enter Rescue Mode. Minimal Used to install the operating system from another source (such as a ...

리눅스 / LVM / 만드는 방법, 수정하는 방법, 삭제하는 방법

1TB 디스크와 2TB 디스크를 추가했다고 하자. 디스크 크기에 맞게 그대로 사용할 수도 있지만, 3TB 하나인 것처럼 사용하거나 1.5TB 두 개인 것처럼 사용하고 싶을 수도 있다. 즉, 물리적인 디스크 크기와 무관하게 자유롭게 볼륨을 만들고 싶은 것이다. 이럴 때 사용하는 것이 LVM(Logical Volume Manager)이다. 여러 개의 볼륨을 하나로 묶은 후 다시 배분하여 사용한다.(이렇게 ...