Linux / Unix:命令显示目录列表
如何使用 Linux 或 Unix 命令行选项显示目录列表?
要查看目录及其内容,请使用 ls 命令。语法为:
要查看目录及其内容,请使用 ls 命令。语法为:
ls
或者
ls -l
示例输出:
drwxr-xr-x 5 vivek vivek 4096 Nov 25 2011 utils drwxr-xr-x 3 vivek vivek 4096 Aug 27 04:06 Videos drwxr-xr-x 7 vivek vivek 4096 Jul 20 18:53 VirtualBox VMs -rw-r--r-- 1 vivek vivek 110103 Oct 29 01:28 virtualenv.py -rw-r--r-- 1 vivek vivek 92900 Oct 29 01:30 virtualenv.pyc -rw-r--r-- 1 vivek vivek 87520 Aug 28 16:38 vivek@backup: ~_08ucaifslkcfuvmosolwdslgivbjdulius.png -rw-r--r-- 1 vivek vivek 82433 Jun 22 22:04 vivek@wks01: ~_00vdsrfnmotuccwrgxxmtrfluxfpyviokp.png -rw-r--r-- 1 vivek vivek 125942 Jul 19 01:25 vivek@wks01: ~_03jgwsanhgqivghcfhomxmruykhukcwiwr.png -rw-r--r-- 1 vivek vivek 125246 Jul 19 01:25 vivek@wks01: ~_03cacoxssdntehfjgjfkmhppjjpynlaxcr.png -rw-r--r-- 1 vivek vivek 150330 Jul 21 00:16 vivek@wks01: ~_040.png -rw-r--r-- 1 vivek vivek 35270 Aug 28 05:00 vivek@wks01: -tmp_07odslsselrwxmibgwqrjtmtenegmdxtre.png -rw-r--r-- 1 vivek vivek 35537 Aug 28 05:01 vivek@wks01: -tmp_07ucaifslkcfuvmosolwdslgivbjdulius.png -rw-r--r-- 1 vivek vivek 729 Jan 24 2012 vpd.properties -rw-r--r-- 1 vivek vivek 0 Jul 20 07:45 weather -rw-r--r-- 1 vivek vivek 1870054 Jul 20 05:02 Workspace 1_03mbhcybkrcxfngliawfrvntmnmfgbjntd.png -rw-r--r-- 1 vivek vivek 1449756 Jul 20 05:04 Workspace 1_03vdsrfnmotuccwrgxxmtrfluxfpyviokp.png -rw-r--r-- 1 vivek vivek 1911247 Jul 21 04:34 Workspace 1_04mbhcybkrcxfngliawfrvntmnmfgbjntd.png -rw-r--r-- 1 vivek vivek 541831 Sep 9 10:57 Workspace 1_10odslsselrwxmibgwqrjtmtenegmdxtre.png
要查看名为 /etc 的目录列表,请输入:
$ ls /etc
或
$ ls -l /etc
有关长格式的更多信息
从 ls 命令手册页中:
The Long Format If the -l option is given, the following information is displayed for each file: file mode, number of links, owner name, group name, MAC label, number of bytes in the file, abbreviated month, day-of-month file was last modified, hour file last modified, minute file last modified, and the pathname. If the modification time of the file is more than 6 months in the past or future, and the -D or -T are not specified, then the year of the last modification is displayed in place of the hour and minute fields. If the owner or group names are not a known user or group name, or the -n option is given, the numeric ID's are displayed. If the file is a character special or block special file, the major and minor device numbers for the file are displayed in the size field. If the file is a symbolic link the pathname of the linked-to file is pre- ceded by ``->''. The listing of a directory's contents is preceded by a labeled total num- ber of blocks used in the file system by the files which are listed as the directory's contents (which may or may not include . and .. and other files which start with a dot, depending on other options). The default block size is 512 bytes. The block size may be set with option -k or environment variable BLOCKSIZE. Numbers of blocks in the output will have been rounded up so the numbers of bytes is at least as many as used by the corresponding file system blocks (which might have a different size). The file mode printed under the -l option consists of the entry type and the permissions. The entry type character describes the type of file, as follows: - Regular file. b Block special file. c Character special file. d Directory. l Symbolic link. p FIFO. s Socket. w Whiteout. The next three fields are three characters each: owner permissions, group permissions, and other permissions. Each field has three character posi- tions: 1. If r, the file is readable; if -, it is not readable. 2. If w, the file is writable; if -, it is not writable. 3. The first of the following that applies: S If in the owner permissions, the file is not exe- cutable and set-user-ID mode is set. If in the group permissions, the file is not executable and set-group-ID mode is set. s If in the owner permissions, the file is exe- cutable and set-user-ID mode is set. If in the group permissions, the file is executable and set- group-ID mode is set. x The file is executable or the directory is search- able. - The file is neither readable, writable, exe- cutable, nor set-user-ID nor set-group-ID mode, nor sticky. (See below.) These next two apply only to the third character in the last group (other permissions). T The sticky bit is set (mode 1000), but not execute or search permission. (See chmod(1) or sticky(7).) t The sticky bit is set (mode 1000), and is search- able or executable. (See chmod(1) or sticky(7).) The next field contains a plus (`+') character if the file has an ACL, or a space (` ') if it does not. The ls utility does not show the actual ACL; use getfacl(1) to do this.