您的位置:首页 > 运维架构 > Linux

linux的ls命令详解(一)

2017-08-28 17:15 330 查看
ls命令是Linux系统中最被频繁使用的命令之一,我相信ls命令应该是你在Linux系统中使用次数最多的命令。我们每天都在频繁地使用ls命令,然而我们可能没有意识到也从来用不到ls命令的所有可用选项。相信当你习惯了多用一些选项的时候,它还是会给你带来一些便利的。

用法:ls [选项][文件]

例如:ls -a apache-tomcat

.   bin  cd..  lib      logs    RELEASE-NOTES  temp     work

..  cd   conf  LICENSE  NOTICE  RUNNING.txt    webapps

List information about the FILEs (the current directory by default).

Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

列出有关文件的信息(默认为当前目录)。 按字母顺序排序的条目,如果没有- cftuvsux也指定排序。长选项的强制参数对于短选项也是必需的(这个段落是系统帮助中的内容,说实话我也不太懂,欢迎大家踊跃探讨)。

 -a, --all   不隐藏任何以. 开始的项目

  -A, --almost-all  列出除. 及.. 以外的任何项目

      --author   与-l 同时使用时列出每个文件的作者(不论是-a还是-A)。例如:

[root@localhost 桌面]# ls -l -a

总用量 18040

drwxr-xr-x.  4 i         i    245 8月  28 17:19    .

drwx------. 14 i      inf     4096 8月  28 15:32   ..

drwxrwxrwx.  9 root     root          182 8月  28 15:40 apache-tomcat

-rw-r--r--.  1 root     root            0 8月  28 16:08 --help

-rw-------.  1 in      in    18499 8月  15 18:29 LinuxVarLog-xiangjie.txt

-rw-r--r--.  1 root     root            0 8月  28 16:08 man

-rw-r--r--.  1 root     root           18 8月  28 17:19 s1

-rw-r--r--.  1 root     root          189 8月  26 11:59 start0822

-rw-r--r--.  1 root     root          189 8月  26 12:14 start1

-rw-r--r--.  1 root     root          189 8月  28 16:10 start2

-rwxrwxrwx.  1 root     root            0 8月  26 12:14 start日志

root@localhost 桌面]# ls  -A -l

总用量 18036

drwxrwxrwx.  9 root     root          182 8月  28 15:40 apache-tomcat

-rwxrw-rw-.  1 i          i  14356480 7月  21 10:37 apache-tomcat-

drwxrwxr-x. 14 i      i     4096 5月  17 2016 bugzilla-5.0.3

-rw-r--r--.  1 root     root            0 8月  28 16:08 --help

-rw-------.  1 in        in    18499 8月  15 18:29 LinuxVarLog-xiangjie.txt

-rw-r--r--.  1 root     root            0 8月  28 16:08 man

-rw-r--r--.  1 root     root           18 8月  28 17:19 s1

-rw-r--r--.  1 root     root          189 8月  26 11:59 start0822

-rw-r--r--.  1 root     root          189 8月  26 12:14 start1

-rw-r--r--.  1 root     root          189 8月  28 16:10 start2

-rwxrwxrwx.  1 root     root            0 8月  26 12:14 start日志

 -l    使用较长格式列出信息,包括文件的权限信息,文件大小,作者,创建时间等。

-Z(大写Z)   Displays only mode, user, group,security context and file name。只显示模式、用户、组、安全上下文和文件名。例如:

[root@localhost 桌面]# ls -Z

drwxrwxrwx. root     root     unconfined_u:object_r:user_home_t:s0 apache-tomcat

-rw-r--r--. root     root     unconfined_u:object_r:user_home_t:s0 --help

-rw-r--r--. root     root     unconfined_u:object_r:user_home_t:s0 man

-rw-r--r--. root     root     unconfined_u:object_r:user_home_t:s0 s1

-rw-r--r--. root     root     unconfined_u:object_r:user_home_t:s0 start0822

-rw-r--r--. root     root     unconfined_u:object_r:user_home_t:s0 start1

-rw-r--r--. root     root     unconfined_u:object_r:user_home_t:s0 start2

-rw-r--r--. root     root     unconfined_u:object_r:user_home_t:s0 start3

-rwxrwxrwx. root     root     unconfined_u:object_r:user_home_t:s0 sta

让我们把-Z和-l对比一下:

ls -l

总用量 18040

drwxrwxrwx.  9 root     root          182 8月  28 15:40 apache-tomcat

-rw-r--r--.  1 root     root            0 8月  28 16:08 --help

-rw-r--r--.  1 root     root            0 8月  28 16:08 man

-rw-r--r--.  2 root     root           18 8月  28 17:19 s1

-rw-r--r--.  1 root     root          189 8月  26 11:59 start0822

-rw-r--r--.  1 root     root          189 8月  26 12:14 start1

-rw-r--r--.  1 root     root          189 8月  28 16:10 start2

-rw-r--r--.  2 root     root           18 8月  28 17:19 start3

-rwxrwxrwx.  1 root     root            0 8月  26 12:14 start日志

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: