Linux ls命令
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
给目录加标识
只给目录加/
实例:
# ls –a #显示所有,包括隐藏文件
. ..dir1dir2 dir3file1file2 file3
# 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
# 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
# touch -m file1 -d "20180311" #修改更改时间
# touch -m file2 -d "20180312" #修改更改时间
# 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
# ll –tr#-r倒序,一般配个-t使用
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
# ll -d /test/ #只显示当前文件或目录的属性
drwxr-xr-x 6 root root 4096 Mar 19 14:42 /test/
# touch -a file2 -d "20180313" #修改访问时间
# touch -a file1 -d "20180314" #修改访问时间
# 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
# 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
# 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
# ll -d /test/ #只显示当前这个目录的属性
drwxr-xr-x 6 root root 4096 Mar 19 14:42 /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 代表最后修改的时间
#ls --color=auto#带颜色显示
# ls -F #给目录后面加上标识(不同的文件可能加的不一样)
dir1/ dir2/dir3/file file1file2file3 test/
# ls –p #只给目录加上“/”
dir1/ dir2/dir3/file file1file2file3 test/
页:
[1]