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:
- If ["$1" = "/? "]
- Then
- Echo "show the files in the directory or subdirectory"
- Echo "DIR [filename] [/O [sortorder] [/S] [/W]"
- Echo "/O sort"
- Echo "sortorder N by name S by size"
- Echo "E by extension D by time"
- Echo "/S show the files in the directory and subdirectory"
- Echo "/W use wide list format"
- Exit 1
- Fi
- I = 0
- Var = ls
- Varapp = ""
- For id
- Do
- If ["$ id" = "/W"]
- Then
- I = 'expr $ I + 1'
- Fi
- If ["$ id" = "/w"]
- Then
- I = 'expr $ I + 1'
- Fi
- Done
- If [$ I-eq 0]
- Then
- Varapp = "-a-l"
- Else
- Varapp = "-a-m"
- Fi
- If [$ #-gt 0]
- Then
- While [$ #-gt 0]
- Do
- Case $1 in
- /OE |/oe |/Oe |/oE) var = $ var $ "-X"
- ;;
- /OD |/od |/Od |/oD) var = $ var $ "-t"
- ;;
- /OS |/OS |/OS |/OS) var = $ var $ "-s"
- ;;
- /ON |/on |/On |/oN) var = $ var
- ;;
- /S |/s) var = $ var $ "-R"
- ;;
- /W |/w) var = $ var
- ;;
- *) Var = $ var "$1"
- Esac
- Shift
- Done
- Fi
- Var = $ var $ varapp
- $ Var
The preceding describes how to use the dir command parameters in linux.