Linux ls命令
更多资料下载,冲击月薪过万,一线经验工程师录制,
干货满满的嵌入式视频教程,请点击淘宝店:wanglitao.taobao.com 
			Linux的ls命令用来显示指定目录下的内容:文件、子目录,甚至一些隐藏的文件等。如果ls命令后面没有指定目录参数,默认会显示当前目录的内容。
root@ubuntu:/# ls
bin cdrom  etc lib lib64 lost+found  mnt  proc  run snap swapfile  tmp  var boot  dev  home  lib32  libx32  media opt root sbin srv sys usr
ls后面可以跟不同的参数,用户可以根据自己需要,显示不同的内容或格式。
- -a:显示所有的文件和目录(包括以.xx开头的文件、当前目录.、上级目录..)
- -l:以列表的形式,详细显示文件的所有信息:类型、owner、大小、读写权限
root@ubuntu:/home/nfs# ls -a
.   a.out bin  etc  lib  mathmodule.ko  proc  sbin  test.ko usr
..  .ash_history  dev  hello.ko  linuxrc  mnt root sys tmp var
root@ubuntu:/home/nfs# ls -l
total 404
-rwxr-xr-x 1 root root   8408 Dec  8 21:44 a.out
drwxr-xr-x 2 root root   4096 Oct 20 18:16 bin
drwxr-xr-x 2 root root   4096 Oct 20 18:16 dev
drwxr-xr-x 4 root root   4096 Oct 20 23:41 etc
-rw-r--r-- 1 root root  86452 Dec 26 05:59 hello.ko
drwxr-xr-x 2 root root   4096 Oct 20 23:31 lib
lrwxrwxrwx 1 root root     11 Oct 20 18:16 linuxrc -> bin/busybox
-rw-r--r-- 1 root root  88648 Dec  5 19:27 mathmodule.ko
drwxr-xr-x 2 root root   4096 Oct 20 21:43 sys
-rw-r--r-- 1 root root 169272 Dec  8 04:33 test.ko
ls后面也可以跟多个参数,多个参数可以分开写,也可以合并在一起,当然也可以使用alias给它定义一个别名,当参数很多很长时,使用起来更加方便。下面三个命令是等价的:
root@ubuntu:/home/nfs# ls -l -a
root@ubuntu:/home/nfs# ls -al
root@ubuntu:/home/nfs# ll
total 416
drwxrwxrwx 14 root root   4096 Dec  8 06:33 ./
drwxr-xr-x 11 root root   4096 Jan 23 18:23 ../
-rwxr-xr-x  1 root root   8408 Dec  8 21:44 a.out*
-rw-------  1 root root    117 Oct 20 20:28 .ash_history
drwxr-xr-x  2 root root   4096 Oct 20 18:16 bin/
drwxr-xr-x  2 root root   4096 Oct 20 18:16 dev/
drwxr-xr-x  4 root root   4096 Oct 20 23:41 etc/
-rw-r--r--  1 root root  86452 Dec 26 05:59 hello.ko
drwxr-xr-x  2 root root   4096 Oct 20 23:31 lib/
lrwxrwxrwx  1 root root     11 Oct 20 18:16 linuxrc -> bin/busybox*
-rw-r--r--  1 root root  88648 Dec  5 19:27 mathmodule.ko
drwxr-xr-x  2 root root   4096 Oct 20 21:43 mnt/
ls其他参数一览
- -A:和-a类似,列出所有文件,但不包括 . 和 .. 这两个 
- -r:反序显示,默认是按首字母顺序显示 
- -R:递归显示,若当前目录下子目录,依次把子目录下的文件也显示出来 
- -t:以文件的修改时间(时间戳)排序显示,最新修改的文件排前面 
- -f:不排序、使能-aU参数,关闭彩色显示 
- -F:在显示的每一项后添加文件类型标识符 - root@ubuntu:/home/nfs# ls -F a.out* dev/ hello.ko linuxrc@ mnt/ root/ sys/ tmp/ var/ bin/ etc/ lib/ mathmodule.ko proc/ sbin/ test.ko usr/- *:表示该文件具有可执行权限
- /:表示目录
- @:表示链接文件
- |:表示命令管道
- =:表示套接字
- 空:普通文件
 
- -i:显示文件的索引节点inode,系统通过inode才能找到其在磁盘上的存储地址 
- -s:显示文件大小,以block为单位 
- -c:相当于-lt连用 
- -m:显示的各个文件之间使用逗号隔开 
- -n:类似于ls -l,不同之处在于用户识别码使用数字直接显示 
- -L:若碰到链接文件,直接显示该链接指向的原始目录或文件 
《Linux三剑客》视频教程,从零开始快速掌握Linux开发常用的工具:Git、Makefile、vim、autotools、debug,免费赠送C语言视频教程,C语言项目实战:学生成绩管理系统。详情请点击淘宝链接:Linux三剑客