zoukankan      html  css  js  c++  java
  • Linux命令(2):ls

    功能说明:

            ls用于列出目标目录中所有的子目录和文件。,是Linux的一个常用命令,是list的缩写。

    命令格式:

            ls [选项] 目录...

    命令参数:   

    -a, –all 列出目录下的所有文件,包括以 . 开头的隐含文件
    -A 同-a,但不列出“.”(表示当前目录)和“..”(表示当前目录的父目录)。
    -c  配合 -lt:根据 ctime 排序及显示 ctime (文件状态最后更改的时间)配合 -l:显示 ctime 但根据名称排序否则:根据 ctime 排序
    -C 每栏由上至下列出项目
    –color[=WHEN] 控制是否使用色彩分辨文件。WHEN 可以是'never'、'always'或'auto'其中之一
    -d, –directory 将目录象文件一样显示,而不是显示其下的文件。
    -D, –dired 产生适合 Emacs 的 dired 模式使用的结果
    -f 对输出的文件不进行排序,-aU 选项生效,-lst 选项失效
    -g 类似 -l,但不列出所有者
    -G, –no-group 不列出任何有关组的信息
    -h, –human-readable 以容易理解的格式列出文件大小 (例如 1K 234M 2G)
    –si 类似 -h,但文件大小取 1000 的次方而不是 1024
    -H, –dereference-command-line 使用命令列中的符号链接指示的真正目的地
    –indicator-style=方式 指定在每个项目名称后加上指示符号<方式>:none (默认),classify (-F),file-type (-p)
    -i, –inode 印出每个文件的 inode 号
    -I, –ignore=样式 不印出任何符合 shell 万用字符<样式>的项目
    -k 即 –block-size=1K,以 k 字节的形式表示文件的大小。
    -l 除了文件名之外,还将文件的权限、所有者、文件大小等信息详细列出来。
    -L, –dereference 当显示符号链接的文件信息时,显示符号链接所指示的对象而并非符号链接本身的信息
    -m 所有项目以逗号分隔,并填满整行行宽
    -o 类似 -l,显示文件的除组信息外的详细信息。   
    -r, –reverse 依相反次序排列
    -R, –recursive 同时列出所有子目录层
    -s, –size 以块大小为单位列出所有文件的大小
    -S 根据文件大小排序
    –sort=WORD 以下是可选用的 WORD 和它们代表的相应选项:
    extension -X status -c
    none -U time -t
    size -S atime -u
    time -t access -u
    version -v use -u
    -t 以文件修改时间排序
    -u 配合 -lt:显示访问时间而且依访问时间排序  配合 -l:显示访问时间但根据名称排序  否则:根据访问时间排序 www.2cto.com  
    -U 不进行排序;依文件系统原有的次序列出项目
    -v 根据版本进行排序
    -w, –width=COLS 自行指定屏幕宽度而不使用目前的数值
    -x 逐行列出项目而不是逐栏列出
    -X 根据扩展名排序
    -1 每行只列出一个文件

    命令案例:

    1、列出test文件所有文件和目录,以及子目录层

    [root@oldboy ~]# ls -lR test/
    test/:
    total 8
    drwxr-xr-x 4 root root 4096 Aug 7 14:11 km
    drwxr-xr-x 2 root root 4096 Aug 7 13:53 kmmiao

    test/km:
    total 8
    drwxr-xr-x 2 root root 4096 Aug 7 13:59 miao
    drwxr-xr-x 2 root root 4096 Aug 7 14:11 test

    2、列出当前目录中有一k开头的目录详细信息。

    [root@oldboy ~]# ls -l *t
    -rw-r--r--. 1 root root 10 Aug 2 22:12 a.txt
    -rw-r--r--. 1 root root 5 Aug 2 21:33 b.txt
    -rw-r--r--. 1 root root 0 Aug 1 18:39 oldboy.txt
    lrwxrwxrwx. 1 root root 7 Aug 2 04:57 one.txt -> two.txt
    -rw-r--r--. 1 root root 22 Aug 2 04:30 two.txt

    test:
    total 8
    drwxr-xr-x 4 root root 4096 Aug 7 14:11 km
    drwxr-xr-x 2 root root 4096 Aug 7 13:53 kmmiao

    3、列出目前工作目录下所有名称是t 开头的档案,并按照时间排序

    [root@oldboy ~]# ls -ltr o*
    -rw-r--r--. 1 root root 0 Aug 1 18:39 oldboy.txt
    lrwxrwxrwx. 1 root root 7 Aug 2 04:57 one.txt -> two.txt

    4、列出目前工作目录下所有档案及目录;(目录后加/,可执行文件后加*)

    [root@oldboy ~]# ls -AF
    .bash_history .tcshrc anaconda-ks.cfg one.txt@
    .bash_logout .viminfo b.txt test/
    .bash_profile 12345 install.log two.txt
    .bashrc 6:20pm install.log.syslog
    .cshrc a.txt oldboy.txt

    5、无参数:显示当前目录下的文件和目录(隐藏文件除外)

    [root@oldboy ~]# ls
    12345 anaconda-ks.cfg install.log.syslog test
    6:20pm b.txt oldboy.txt two.txt
    a.txt install.log one.txt

    6、可视化显示文件类型

    [root@oldboy ~]# ls -F
    12345 anaconda-ks.cfg install.log.syslog test/
    6:20pm b.txt oldboy.txt two.txt
    a.txt install.log one.txt@

    • / : 目录
    • nothing : 普通文件.
    • @ :符号链接文件
    • * :可执行文件

    7、列出/etc/目录下以字母a开头且以字母e结尾的目录和文件。

    [root@oldboy ~]# ls /etc/a*e
    /etc/adjtime
    [root@oldboy ~]#



    共相互学习,共享资源,共享成果。
    Linux运维开发群:245397468
    Mysql DBA交流群:261677620
  • 相关阅读:
    排序_简单选择排序
    排序_冒泡排序
    笔试_阿里_逆波兰表达式
    刷题_牛客_大整数排序
    刷题_牛客_字符串编码
    刷题_thinkinginjava_吸血鬼数字
    刷题_牛客_超级素数幂
    刷题_LeetCode_Two Sum
    刷题_LeetCode_Reverse Integer
    854. Floyd求最短路(模板)
  • 原文地址:https://www.cnblogs.com/miaokm/p/3897414.html
Copyright © 2011-2022 走看看