Linux ls命令
顯示目錄內容列表,輸出信息可以進行彩色加高亮顯示,以分區不同類型的文件。
語法:
touch [選項] [參數]
選項 | 解釋 | 例子 |
-a,--all | 顯示所有文件,包括以“.”開頭的隱藏文件 | ls –a / 顯示根下面的所有文件 |
-l | 長格式顯示 | Ls –l 顯示文件屬性 |
-h | 以1024位進制的顯示文件大小 | |
-d | 顯示當前目錄 | Ls –d /tmp |
-t | 按照修改時間排序,默認從近到遠 | Ls –t / |
-r | 倒序,經常配合-t使用 | Ls –tr / |
-c | 配合-lt 根據ctime(文件的訪問時間ACCESS) | |
-G | 不列出任何有關組的信息 | |
-F | 給目錄加標識 | (不同的文件加不同的標識) |
-p | 給目錄加標識 | 只給目錄加/ |
實例:
[root@zsf test]# ls –a . .. dir1 dir2 dir3 file1 file2 file3 [root@zsf test]# ls -l /ll #長格式顯示 total 12 drwxr-xr-x 2 root root 4096 Mar 19 14:23 dir1 drwxr-xr-x 2 root root 4096 Mar 19 14:23 dir2 [root@zsf test]# ll –h #以K,M,G來顯示文件大小 total 12K drwxr-xr-x 2 root root 4.0K Mar 19 14:23 dir1 drwxr-xr-x 2 root root 4.0K Mar 19 14:23 dir2 [root@zsf test]# touch -m file1 -d "20180311" #修改更改時間 [root@zsf test]# touch -m file2 -d "20180312" #修改更改時間 [root@zsf test]# ll –t #按照修改時間來排序,由近到遠,默認是按照修改時間 total 0 -rw-r--r-- 1 root root 0 Mar 12 00:00 file2 -rw-r--r-- 1 root root 0 Mar 11 00:00 file1 [root@zsf test]# ll –tr #-r倒序,一般配個 total 0 -rw-r--r-- 1 root root 0 Mar 11 00:00 file1 -rw-r--r-- 1 root root 0 Mar 12 00:00 file2
[root@zsf test]# ll -d /test/ #只顯示當前文件或目錄的屬性 drwxr-xr-x 6 root root 4096 Mar 19 14:42 /test/ [root@zsf test]# touch -a file2 -d "20180313" #修改訪問時間 [root@zsf test]# touch -a file1 -d "20180314" #修改訪問時間 [root@zsf test]# ll -tc #按照文件的訪問時間來排序 total 0 -rw-r--r-- 1 root root 0 Mar 19 14:47 file1 -rw-r--r-- 1 root root 0 Mar 19 14:47 file2 [root@zsf test]# stat file2 查看狀態 File: `file2' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 521236 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2018-03-13 00:00:00.000000000 -0400 Modify: 2018-03-12 00:00:00.000000000 -0400 Change: 2018-03-19 14:47:13.681005838 -0400 [root@zsf test]# stat file1 File: `file1' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 521234 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2018-03-14 00:00:00.000000000 -0400 Modify: 2018-03-11 00:00:00.000000000 -0500 Change: 2018-03-19 14:47:19.547994463 -0400 |
[root@zsf test]# ll -d /test/ #只顯示當前這個目錄的屬性 drwxr-xr-x 6 root root 4096 Mar 19 14:42 /test/ |
[root@zsf test]# ll -Gd /test/ #不顯示屬組的信息 drwxr-xr-x 6 root 4096 Mar 19 14:42 /test/ |
長格式顯示說明:
-rw-r—r--. 1 root root 0 Mar 12 16:18 1.sh 第一位:代表這個文件的類型,-代表文件、d代表目錄,l代表鏈接文件, 後面9位:每3位分別代表,屬主,屬組,其他人的權限,r讀,w寫,x執行,分別代表421 1:代表被鏈接了幾次 root:屬主 root:屬組 0 :代表大小,單位bits Mar 12 16:18 代表最後修改的時間 [root@zsf test]#ls --color=auto #帶顏色顯示 [root@zsf test]# ls -F #給目錄後面加上標識(不同的文件可能加的不一樣) dir1/ dir2/ dir3/ file file1 file2 file3 test/ [root@zsf test]# ls –p #只給目錄加上“/” dir1/ dir2/ dir3/ file file1 file2 file3 test/ |
Linux ls命令