1. ls -d *
  1. find . -type d -maxdepth 1

amosli@amosli-pc:~$ ls -d * %APPDATA% develop many sorted.txt workspace bank Documents Music space 下载

2. find . -type d -maxdepth 1

如果不加-maxdepth 参数的话那么将会有无穷多目录被列出来。
ls - 列出目录列表或文件列表 - 图1
amosli@amosli-pc:~$ find . -type d -maxdepth 1 ./Videos ./Public ./%APPDATA% ./.kde ./.gnome2 ./Music
ls - 列出目录列表或文件列表 - 图2

3.ls -F | grep ‘/$’
使用linux管道命令,grep查找 ‘/$’ 以/结尾的,也即是目录

amosli@amosli-pc:~$ ls -F | grep’/$’ %APPDATA%/ bank/ Desktop/ develop/ Documents/

4.ls -l | grep ‘^d’

amosli@amosli-pc:~$ ls -l | grep’^d’ drwxr-xr-x 3 amosli amosli 4096 6月 222013 %APPDATA% drwxr-xr-x 36 amosli amosli 4096 12月 2017:44 bank drwxr-xr-x 4 amosli amosli 4096 12月 2800:33 Desktop drwxrwxr-x 13 amosli amosli 4096 12月 2119:11 develop drwxr-xr-x 3 amosli amosli 4096 7月 900:58 Documents

命令:ls

详细解释:

  1. -l use a long listing format 以长列表方式显示(详细信息方式)
  2. -t sort by modification time 按修改时间排序(最新的在最前面)
  3. -r reverse order while sorting (反序)

Linux:ls按照修改时间排序显示

  1. # 按照时间降序
  2. ls -lt
  3. # 按照时间升序
  4. ls -ltr
  1. root@zabbix-unify:/# # 按照时间降序
  2. root@zabbix-unify:/# ls -lt
  3. total 0
  4. drwxrwxrwt 1 root root 68 Nov 30 17:47 tmp
  5. drwxr-xr-x 1 root root 43 Nov 26 13:39 run
  6. drwxr-xr-x 16 root root 4020 Nov 26 13:39 dev
  7. drwxr-xr-x 1 root root 77 Nov 26 13:39 apps
  8. dr-xr-xr-x 1175 root root 0 Nov 26 13:39 proc
  9. drwxr-xr-x 1 root root 20 Nov 26 13:39 etc
  10. dr-xr-xr-x 13 root root 0 Nov 25 19:53 sys
  11. dr-xr-xr-x 1175 root root 0 Nov 25 19:53 host
  12. drwx------ 2 root root 37 Jun 9 15:31 root
  13. drwxr-xr-x 1 root root 45 Jun 9 15:31 var
  14. drwxr-xr-x 2 root root 6 Jun 9 15:27 media
  15. drwxr-xr-x 2 root root 6 Jun 9 15:27 mnt
  16. drwxr-xr-x 2 root root 6 Jun 9 15:27 opt
  17. drwxr-xr-x 2 root root 6 Jun 9 15:27 srv
  18. drwxr-xr-x 1 root root 19 Jun 9 15:27 usr
  19. lrwxrwxrwx 1 root root 7 Jun 9 15:27 bin -> usr/bin
  20. lrwxrwxrwx 1 root root 7 Jun 9 15:27 lib -> usr/lib
  21. lrwxrwxrwx 1 root root 9 Jun 9 15:27 lib32 -> usr/lib32
  22. lrwxrwxrwx 1 root root 9 Jun 9 15:27 lib64 -> usr/lib64
  23. lrwxrwxrwx 1 root root 10 Jun 9 15:27 libx32 -> usr/libx32
  24. lrwxrwxrwx 1 root root 8 Jun 9 15:27 sbin -> usr/sbin
  25. drwxr-xr-x 2 root root 6 Apr 15 2020 boot
  26. drwxr-xr-x 2 root root 6 Apr 15 2020 home
  27. root@zabbix-unify:/#
  28. root@zabbix-unify:/# # 按照时间升序
  29. root@zabbix-unify:/# ls -ltr
  30. total 0
  31. drwxr-xr-x 2 root root 6 Apr 15 2020 home
  32. drwxr-xr-x 2 root root 6 Apr 15 2020 boot
  33. lrwxrwxrwx 1 root root 8 Jun 9 15:27 sbin -> usr/sbin
  34. lrwxrwxrwx 1 root root 10 Jun 9 15:27 libx32 -> usr/libx32
  35. lrwxrwxrwx 1 root root 9 Jun 9 15:27 lib64 -> usr/lib64
  36. lrwxrwxrwx 1 root root 9 Jun 9 15:27 lib32 -> usr/lib32
  37. lrwxrwxrwx 1 root root 7 Jun 9 15:27 lib -> usr/lib
  38. lrwxrwxrwx 1 root root 7 Jun 9 15:27 bin -> usr/bin
  39. drwxr-xr-x 1 root root 19 Jun 9 15:27 usr
  40. drwxr-xr-x 2 root root 6 Jun 9 15:27 srv
  41. drwxr-xr-x 2 root root 6 Jun 9 15:27 opt
  42. drwxr-xr-x 2 root root 6 Jun 9 15:27 mnt
  43. drwxr-xr-x 2 root root 6 Jun 9 15:27 media
  44. drwxr-xr-x 1 root root 45 Jun 9 15:31 var
  45. drwx------ 2 root root 37 Jun 9 15:31 root
  46. dr-xr-xr-x 1172 root root 0 Nov 25 19:53 host
  47. dr-xr-xr-x 13 root root 0 Nov 25 19:53 sys
  48. drwxr-xr-x 1 root root 20 Nov 26 13:39 etc
  49. dr-xr-xr-x 1172 root root 0 Nov 26 13:39 proc
  50. drwxr-xr-x 1 root root 77 Nov 26 13:39 apps
  51. drwxr-xr-x 16 root root 4020 Nov 26 13:39 dev
  52. drwxr-xr-x 1 root root 43 Nov 26 13:39 run
  53. drwxrwxrwt 1 root root 68 Nov 30 17:47 tmp
  54. root@zabbix-unify:/#

-l use a long listing format 以长列表方式显示(详细信息方式)
-t sort by modification time 按修改时间排序(最新的在最前面)
-r reverse order while sorting (反序)

按标准时间格式, 显示时间, 便于 GREP 查找等操作

详细解释:

  1. --time-style=TIME_STYLE time/date format with -l; see TIME_STYLE below

The TIME_STYLE argument can be full-iso, long-iso, iso, locale, or +FORMAT. FORMAT is interpreted like in date(1). If FORMAT is FORMAT1FORMAT2, then FORMAT1 applies to non-recent files and FORMAT2 to recent files. TIME_STYLE prefixed with ‘posix-‘ takes effect only outside the POSIX locale. Also the TIME_STYLE environment variable sets the default style to use.

  1. ls -al --time-style=long-iso

image.png