码迷,mamicode.com
首页 > 系统相关 > 详细

Linux 基本命令(一)--ls 常用命令

时间:2019-07-30 10:53:32      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:update   linu   div   src   设备文件   一个   tmp   目录文件   class   

2019-07-30


 以下例举的是常用参数

ls 

只显示文件、文件目录等名称,不显示其他信息。

[root@localhost opt]# ls
test1   test11  test13  test15  test2  test4  test6  test8
test10  test12  test14  test16  test3  test5  test7  test9

ls 目录   #显示某个目录内的文件、文件目录等名称

ls -a

查看当前目录所有文件(包含隐藏文件)

ls -a 目录   #某目录下的所有文件

[root@localhost var]# ls -a
.   adm    crash  empty  gopher    lib    lock  mail  opt       run    tmp       yp
..  cache  db     games  kerberos  local  log   nis   preserve  spool  .updated
[root@localhost var]# ls -a /opt/test10/
.  ..  1  12  jkl

ls -l

(参数是字母L的小写) 用来查看详细的文件信息

ls -l 目录   #目录内所有文件的详细信息,不加目录默认是当前目录

[root@localhost opt]# ls -l
total 0
drwxr-xr-x. 3 root root 36 Jul 29 21:22 test10
drwxr-xr-x. 2 root root  6 Jul 29 21:06 test12
-rw-r--r--. 1 root root  0 Jul 29 21:05 test2
-rw-r--r--. 1 root root  0 Jul 29 21:05 test4
-rw-r--r--. 1 root root  0 Jul 29 21:05 test8
-rw-r--r--. 1 root root  0 Jul 29 21:05 test9
[root@localhost opt]# ls -l test10
total 0
-rw-r--r--. 1 root root 0 Jul 29 21:21 1
-rw-r--r--. 1 root root 0 Jul 29 21:21 12
drwxr-xr-x. 2 root root 6 Jul 29 21:22 jkl

技术图片

第一个字符文件类型中:

  d:目录文件

  l:链接文件

  b:块设备文件

  c:字符设备文件

  p:管道文件

  -: 表示普通文件

ls -S

按文件大-->小排序

ls -rS

按文件小-->大排序

 (-S一般搭配 -l参数,即 -lS)

[root@localhost var]# ls -lS
total 8
drwxr-xr-x. 24 root root 4096 May 12 23:15 lib
drwxr-xr-x.  7 root root 4096 Jul 29 20:56 log
drwxr-xr-x.  8 root root   87 May 12 23:14 spool
drwxrwxrwt.  3 root root   85 Jul 29 21:03 tmp
drwxr-xr-x.  5 root root   44 May 12 23:14 cache
drwxr-xr-x.  3 root root   34 Jul 29 21:00 db
drwxr-xr-x.  3 root root   18 May 12 23:14 empty
drwxr-xr-x.  3 root root   18 Jan 29 12:32 kerberos
lrwxrwxrwx.  1 root root   11 May 12 23:11 lock -> ../run/lock
lrwxrwxrwx.  1 root root   10 May 12 23:11 mail -> spool/mail
drwxr-xr-x.  2 root root    6 Apr 11  2018 adm
drwxr-xr-x.  2 root root    6 Apr 11  2018 preserve
lrwxrwxrwx.  1 root root    6 May 12 23:11 run -> ../run
drwxr-xr-x.  2 root root    6 Apr 11  2018 yp
[root@localhost var]# ls -lrS
total 8
drwxr-xr-x.  2 root root    6 Apr 11  2018 yp
lrwxrwxrwx.  1 root root    6 May 12 23:11 run -> ../run
drwxr-xr-x.  2 root root    6 Apr 11  2018 preserve
drwxr-xr-x.  2 root root    6 Apr 11  2018 adm
lrwxrwxrwx.  1 root root   10 May 12 23:11 mail -> spool/mail
lrwxrwxrwx.  1 root root   11 May 12 23:11 lock -> ../run/lock
drwxr-xr-x.  3 root root   18 Jan 29 12:32 kerberos
drwxr-xr-x.  3 root root   18 May 12 23:14 empty
drwxr-xr-x.  3 root root   34 Jul 29 21:00 db
drwxr-xr-x.  5 root root   44 May 12 23:14 cache
drwxrwxrwt.  3 root root   85 Jul 29 21:03 tmp
drwxr-xr-x.  8 root root   87 May 12 23:14 spool
drwxr-xr-x.  7 root root 4096 Jul 29 20:56 log
drwxr-xr-x. 24 root root 4096 May 12 23:15 lib

ls -t

按时间近-->远排序

ls -tr

按时间远-->近排序

(一般与参数-l同时使用)

[root@localhost var]# ls -lt
total 8
drwxrwxrwt.  3 root root   85 Jul 29 21:03 tmp
drwxr-xr-x.  3 root root   34 Jul 29 21:00 db
drwxr-xr-x.  7 root root 4096 Jul 29 20:56 log
drwxr-xr-x. 24 root root 4096 May 12 23:15 lib
drwxr-xr-x.  8 root root   87 May 12 23:14 spool
drwxr-xr-x.  3 root root   18 May 12 23:14 empty
drwxr-xr-x.  5 root root   44 May 12 23:14 cache
lrwxrwxrwx.  1 root root   10 May 12 23:11 mail -> spool/mail
lrwxrwxrwx.  1 root root   11 May 12 23:11 lock -> ../run/lock
lrwxrwxrwx.  1 root root    6 May 12 23:11 run -> ../run
drwxr-xr-x.  2 root root    6 Apr 24 10:03 crash
drwxr-xr-x.  3 root root   18 Jan 29 12:32 kerberos
drwxr-xr-x.  2 root root    6 Apr 11  2018 adm
drwxr-xr-x.  2 root root    6 Apr 11  2018 games
drwxr-xr-x.  2 root root    6 Apr 11  2018 gopher
drwxr-xr-x.  2 root root    6 Apr 11  2018 local
drwxr-xr-x.  2 root root    6 Apr 11  2018 nis
drwxr-xr-x.  2 root root    6 Apr 11  2018 opt
drwxr-xr-x.  2 root root    6 Apr 11  2018 preserve
drwxr-xr-x.  2 root root    6 Apr 11  2018 yp
[root@localhost var]# ls -ltr
total 8
drwxr-xr-x.  2 root root    6 Apr 11  2018 yp
drwxr-xr-x.  2 root root    6 Apr 11  2018 preserve
drwxr-xr-x.  2 root root    6 Apr 11  2018 opt
drwxr-xr-x.  2 root root    6 Apr 11  2018 nis
drwxr-xr-x.  2 root root    6 Apr 11  2018 local
drwxr-xr-x.  2 root root    6 Apr 11  2018 gopher
drwxr-xr-x.  2 root root    6 Apr 11  2018 games
drwxr-xr-x.  2 root root    6 Apr 11  2018 adm
drwxr-xr-x.  3 root root   18 Jan 29 12:32 kerberos
drwxr-xr-x.  2 root root    6 Apr 24 10:03 crash
lrwxrwxrwx.  1 root root    6 May 12 23:11 run -> ../run
lrwxrwxrwx.  1 root root   11 May 12 23:11 lock -> ../run/lock
lrwxrwxrwx.  1 root root   10 May 12 23:11 mail -> spool/mail
drwxr-xr-x.  5 root root   44 May 12 23:14 cache
drwxr-xr-x.  3 root root   18 May 12 23:14 empty
drwxr-xr-x.  8 root root   87 May 12 23:14 spool
drwxr-xr-x. 24 root root 4096 May 12 23:15 lib
drwxr-xr-x.  7 root root 4096 Jul 29 20:56 log
drwxr-xr-x.  3 root root   34 Jul 29 21:00 db
drwxrwxrwt.  3 root root   85 Jul 29 21:03 tmp

ls -h

超过1000字节的文件以K为单位显示,一般-l同时使用

[root@localhost var]# ls -lh
total 8.0K
drwxr-xr-x.  2 root root    6 Apr 11  2018 adm
drwxr-xr-x.  5 root root   44 May 12 23:14 cache
drwxr-xr-x.  2 root root    6 Apr 24 10:03 crash
drwxr-xr-x.  3 root root   34 Jul 29 21:00 db
drwxr-xr-x.  3 root root   18 May 12 23:14 empty
drwxr-xr-x.  2 root root    6 Apr 11  2018 games
drwxr-xr-x.  2 root root    6 Apr 11  2018 gopher
drwxr-xr-x.  3 root root   18 Jan 29 12:32 kerberos
drwxr-xr-x. 24 root root 4.0K May 12 23:15 lib
drwxr-xr-x.  2 root root    6 Apr 11  2018 local
lrwxrwxrwx.  1 root root   11 May 12 23:11 lock -> ../run/lock
drwxr-xr-x.  7 root root 4.0K Jul 29 20:56 log
lrwxrwxrwx.  1 root root   10 May 12 23:11 mail -> spool/mail
drwxr-xr-x.  2 root root    6 Apr 11  2018 nis
drwxr-xr-x.  2 root root    6 Apr 11  2018 opt
drwxr-xr-x.  2 root root    6 Apr 11  2018 preserve
lrwxrwxrwx.  1 root root    6 May 12 23:11 run -> ../run
drwxr-xr-x.  8 root root   87 May 12 23:14 spool
drwxrwxrwt.  3 root root   85 Jul 29 21:03 tmp
drwxr-xr-x.  2 root root    6 Apr 11  2018 yp

 

Linux 基本命令(一)--ls 常用命令

标签:update   linu   div   src   设备文件   一个   tmp   目录文件   class   

原文地址:https://www.cnblogs.com/fqxy/p/11268393.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!