Linux 基本命令--ls 常用命令

Posted fqxy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 基本命令--ls 常用命令相关的知识,希望对你有一定的参考价值。

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 常用命令的主要内容,如果未能解决你的问题,请参考以下文章

Linux 基本命令--ls 常用命令

linux的常用命令有那些

Linux 常用基本命令总结

linux常用基本命令

Linux常用基本命令

linux 常用的基本命令