ls [OPTION]... [FILE]...
List information about the FILEs : 顯示當(dāng)前目錄或指定目錄的內(nèi)容
-
常用選項(xiàng):
-a:do not ignore entries starting with . 不忽略.開(kāi)頭的文件 -l:use a long listing format 以長(zhǎng)格式顯示額外信息 -A:do not list implied . and .. 顯示藏藏文件,且不顯示.和..目錄 -d:list directories themselves, not their contents 顯示目錄屬性 -R:list subdirectories recursively 遞歸顯示子目錄內(nèi)容 -1:list one file per line 一行只顯示一個(gè)文件名稱 -S:sort by file size 文件從大到小排序 -t:sort by modification time, newest first 按mtime排序 -u:with -lt: sort by, and show, access time 配合-t選項(xiàng),按atime排序 -x:list entries by lines instead of by columns 按文件后綴順序 -r:reverse order while sorting 反向排序 --full-time:列出完整的日期與時(shí)間, -
直接 ls ../ 可以顯示當(dāng)前父目錄的屬性,等于當(dāng)前目錄下的.目錄
[xzt7566@centos7-test ~]$ ll -lai total 60 51753457 drwx------. 16 xzt7566 xzt7566 4096 May 4 00:43 . 當(dāng)前目錄下的.目錄 [xzt7566@centos7-test ~]$ ll -lai ../ total 4 51753457 drwx------. 16 xzt7566 xzt7566 4096 May 4 00:43 xzt7566 父目錄

-
下例沒(méi)有任何選項(xiàng),但有多個(gè)參數(shù):根目錄和boot目錄.
xzt7566@xzt7566-virtual-machine:~/下載$ ls / /boot /: bin cdrom etc initrd.img lib lib64 lost+found mnt proc run snap swapfile tmp var boot dev home initrd.img.old lib32 libx32 media opt root sbin srv sys usr vmlinuz /boot: config-5.0.0-13-generic initrd.img-5.0.0-13-generic memtest86+.elf System.map-5.0.0-13-generic grub memtest86+.bin memtest86+_multiboot.bin vmlinuz-5.0.0-13-generic -
-d:目錄. 使用-d顯示目錄屬性,不使用-d則顯示目錄下的文件及目錄屬性.
[xzt7566@centos7-test Downloads]$ ls -ld test drwxrwxr-x. 2 xzt7566 xzt7566 28 Apr 27 19:24 test [xzt7566@centos7-test Downloads]$ ls -l test total 0 -rw-rw-r--. 1 xzt7566 xzt7566 0 Apr 27 13:32 1.1 -rw-rw-r--. 1 xzt7566 xzt7566 0 Apr 27 13:32 2.1 -
-i:inode號(hào),-h:易讀易識(shí),--time-style:更改默認(rèn)的時(shí)間顯示格式.
xzt7566@xzt7566-virtual-machine:~/下載$ ls -lhi --time-style '+%Y-%m-%d %H:%M:%S' 總用量 4.0K 1063576 drwxr-xr-x 3 xzt7566 xzt7566 4.0K 2019-04-26 11:45:27 test -
以下這種顯示大小及時(shí)間的方式更容易讓人習(xí)慣,也可以自定成命令別名.
[xzt7566@centos7-test test]$ alias li="ls -lAhi --time-style '+%Y/%m/%d %H:%M:%S'" [xzt7566@centos7-test test]$ li total 0 51757814 -rw-rw-r--. 1 xzt7566 xzt7566 0 2019/04/27 13:32:58 1.1 51757822 -rw-rw-r--. 1 xzt7566 xzt7566 0 2019/04/27 13:32:58 2.1 17549358 drwxrwxr-x. 2 xzt7566 xzt7566 6 2019/04/27 19:26:20 test -
可以使用下列方法加入到配置中,以后啟動(dòng)即有效.
[xzt7566@centos7-test test]$ cat >> /home/xzt7566/.bashrc alias li="ls -lAhi --time-style '+%Y/%m/%d %H:%M:%S'" Ctrl+D -
-S:從大到小排列,加上-r則從小到大排列.
[xzt7566@centos7-test etc]$ pwd /etc [xzt7566@centos7-test etc]$ li -Sr 使用剛才定義的指令li . 17237348 -rw-r--r--. 1 root root 15K 2018/10/31 08:17:07 autofs.conf 17243539 -rw-r--r--. 1 root root 22K 2018/04/11 09:32:28 brltty.conf 17237353 -rw-r--r--. 1 root root 27K 2018/10/31 01:05:19 dnsmasq.conf 18160629 -rw-r--r--. 1 root root 80K 2019/04/22 15:39:18 ld.so.cache 16799293 -rw-r--r--. 1 root root 655K 2013/06/07 22:31:32 services -
-t:以時(shí)間順序排列,加上-r則從舊到新.
[xzt7566@centos7-test etc]$ pwd /etc [xzt7566@centos7-test etc]$ li -tr 使用改才定義的指令li . 33735601 drwxr-xr-x. 2 root root 4.0K 2019/04/22 15:39:12 alternatives 18160629 -rw-r--r--. 1 root root 80K 2019/04/22 15:39:18 ld.so.cache 147162 drwxr-xr-x. 2 root root 206 2019/04/23 14:51:51 yum.repos.d 17666355 -rw-r--r--. 1 root root 13 2019/04/25 11:33:12 hostname 17548207 -rw-r--r--. 1 root root 80 2019/04/26 13:52:27 resolv.conf 16777281 drwxr-xr-x. 143 root root 8.0K 2019/04/26 13:52:27 . 51000843 drwxr-xr-x. 5 root lp 4.0K 2019/04/26 14:00:43 cups -
特殊字符及通配符示例.計(jì)算機(jī)基礎(chǔ):Linux特殊字符
[xzt7566@centos7-test Downloads]$ ls 列出測(cè)試內(nèi)容. 1 1.c 1.cpp 1.h 3.c 3.cpp 5a9.sh 5b9.sh 5e9.sh a.out readme txt [xzt7566@centos7-test Downloads]$ ls 1.* 1開(kāi)頭,有后綴,后綴不限制的文件. 1.c 1.cpp 1.h [xzt7566@centos7-test Downloads]$ ls 1.? 1開(kāi)頭,有后綴,后綴一個(gè)字符的文件. 1.c 1.h [xzt7566@centos7-test Downloads]$ ls [1-5]*.* 1到5開(kāi)頭,有后綴,其他不限制的文件. 1.c 1.cpp 1.h 3.c 3.cpp 5a9.sh 5b9.sh 5e9.sh [xzt7566@centos7-test Downloads]$ ls [!1a]* 不以1,a開(kāi)頭,其他不限制的文件. 3.c 3.cpp 5a9.sh 5b9.sh 5e9.sh readme txt [xzt7566@centos7-test Downloads]$ ls [1-4]*.[a-e]* 名稱以1到4開(kāi)頭,后綴從a到e開(kāi)頭的文件. 1.c 1.cpp 3.c 3.cpp [xzt7566@centos7-test Downloads]$ ls [a-Z0-9].* 顯示不用特殊符號(hào)開(kāi)頭的,后綴無(wú)限制的文件. 1.c 1.cpp 1.h 3.c 3.cpp a.out [xzt7566@centos7-test test]$ touch {1..11}{a..i}.nc [xzt7566@centos7-test test]$ ls 10a.nc 10i.nc 11h.nc 1g.nc 2f.nc 3e.nc 4d.nc 5c.nc 6b.nc 7a.nc 7i.nc 8h.nc 9g.nc 10b.nc 11a.nc 11i.nc 1h.nc 2g.nc 3f.nc 4e.nc 5d.nc 6c.nc 7b.nc 8a.nc 8i.nc 9h.nc 10c.nc 11b.nc 1a.nc 1i.nc 2h.nc 3g.nc 4f.nc 5e.nc 6d.nc 7c.nc 8b.nc 9a.nc 9i.nc 10d.nc 11c.nc 1b.nc 2a.nc 2i.nc 3h.nc 4g.nc 5f.nc 6e.nc 7d.nc 8c.nc 9b.nc 10e.nc 11d.nc 1c.nc 2b.nc 3a.nc 3i.nc 4h.nc 5g.nc 6f.nc 7e.nc 8d.nc 9c.nc 10f.nc 11e.nc 1d.nc 2c.nc 3b.nc 4a.nc 4i.nc 5h.nc 6g.nc 7f.nc 8e.nc 9d.nc 10g.nc 11f.nc 1e.nc 2d.nc 3c.nc 4b.nc 5a.nc 5i.nc 6h.nc 7g.nc 8f.nc 9e.nc 10h.nc 11g.nc 1f.nc 2e.nc 3d.nc 4c.nc 5b.nc 6a.nc 6i.nc 7h.nc 8g.nc 9f.nc [xzt7566@centos7-test test]$ ls {1..4}{a..e}.nc 1a.nc 1c.nc 1e.nc 2b.nc 2d.nc 3a.nc 3c.nc 3e.nc 4b.nc 4d.nc 1b.nc 1d.nc 2a.nc 2c.nc 2e.nc 3b.nc 3d.nc 4a.nc 4c.nc 4e.nc [xzt7566@centos7-test test]$ touch {01..12}a.nc [xzt7566@centos7-test test]$ ls 01a.nc 02a.nc 03a.nc 04a.nc 05a.nc 06a.nc 07a.nc 08a.nc 09a.nc 10a.nc 11a.nc 12a.nc [xzt7566@centos7-test test]$ ls 0[1..38]a.nc 這里的.無(wú)效,就等于[138]三個(gè)字符 01a.nc 03a.nc 08a.nc [xzt7566@centos7-test test]$ ls 0[1-38]a.nc 這里的-有效,等于從1到3和8.共四個(gè)字符 01a.nc 02a.nc 03a.nc 08a.nc