Linux basic commands (a) - ls commonly used commands

2019-07-30


 The following example is the common parameters

ls 

Show only files, directories and other names, do not display additional information.

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

# ls displays the file directory, the file directory within a directory name, etc.

ls -a

View all files in the current directory (including hidden files)

All files in a directory # ls -a directory

[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

(Lowercase letter L parameters) to view detailed file information

For more information about all the files in the directory # ls -l directory, without the default directory is the current directory

[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

The first character of the file types:

  d : directory file

  L : link file

  B : block device file

  c : character device file

  the p- : pipe file

  -:  represents a normal file

ls -S

By file size -> Small sorting

ls -rS

By file small -> large order

 (-S -l with general parameters, namely -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

Near by time -> Sort far

Likewise -tr

Time away -> Near sorting

(Typically used with parameter -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

More than 1,000 byte file in K show general use -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

 

Guess you like

Origin www.cnblogs.com/fqxy/p/11268393.html