Application of dir command parameters in linux

Source: Internet
Author: User
The following is how to use the dir command parameters in linux: the dir command parameters in linux support the following command format: dir [filename] [O [sortorder] [

The following describes how to use the dir command parameters in linux.

In linux, the dir command parameter function is as follows:

In linux, the dir command parameters support the following command formats:

DIR [filename] [/O [sortorder] [/S] [/W]

In linux, the dir command parameters are case-insensitive and support multiple parameters.

The following parameters are supported:

/ON sort by name

/OE sort by extension

/OS sort by size

/OD sort by modification time

/S display subdirectory files

/W adopts the wide List format

1. in linux, the idea of dir command parameters is to construct the corresponding command string (var) in DOS based on the judgment of each parameter and run it.

2. because we cannot determine the number of parameters in the command in advance, use the shift statement to shift the parameter left and use the case statement to determine the $1 parameter, add the corresponding bash command parameters to the end of the command string to be run.

3. the dir command parameter in linux corresponds to ls-a-l, and dir/w corresponds to ls-a-m. This indicates whether "/w" or "/W" exists in $ *. the specific method is to record the number of occurrences of "/w" or "/W, if the last number of times is 0, the initial value of the command string to be run is ls-a-l. Otherwise, it is ls-a-m. Then, process other parameters (using the case statement ).

Dir command parameter code in linux:

  1. If ["$1" = "/? "]
  2. Then
  3. Echo "show the files in the directory or subdirectory"
  4. Echo "DIR [filename] [/O [sortorder] [/S] [/W]"
  5. Echo "/O sort"
  6. Echo "sortorder N by name S by size"
  7. Echo "E by extension D by time"
  8. Echo "/S show the files in the directory and subdirectory"
  9. Echo "/W use wide list format"
  10. Exit 1
  11. Fi
  12. I = 0
  13. Var = ls
  14. Varapp = ""
  15. For id
  16. Do
  17. If ["$ id" = "/W"]
  18. Then
  19. I = 'expr $ I + 1'
  20. Fi
  21. If ["$ id" = "/w"]
  22. Then
  23. I = 'expr $ I + 1'
  24. Fi
  25. Done
  26. If [$ I-eq 0]
  27. Then
  28. Varapp = "-a-l"
  29. Else
  30. Varapp = "-a-m"
  31. Fi
  32. If [$ #-gt 0]
  33. Then
  34. While [$ #-gt 0]
  35. Do
  36. Case $1 in
  37. /OE |/oe |/Oe |/oE) var = $ var $ "-X"
  38. ;;
  39. /OD |/od |/Od |/oD) var = $ var $ "-t"
  40. ;;
  41. /OS |/OS |/OS |/OS) var = $ var $ "-s"
  42. ;;
  43. /ON |/on |/On |/oN) var = $ var
  44. ;;
  45. /S |/s) var = $ var $ "-R"
  46. ;;
  47. /W |/w) var = $ var
  48. ;;
  49. *) Var = $ var "$1"
  50. Esac
  51. Shift
  52. Done
  53. Fi
  54. Var = $ var $ varapp
  55. $ Var
The preceding describes how to use the dir command parameters in linux.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.