Get the App
SLTechnology News&Howtos  ›  Servers  › 

Application of dir Command parameters in linux

Shulou Source: shulou.com Published: 2022-06-01 17:56:50 10月27日 Update

This article mainly talks about "the application of dir command parameters in linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "the application of dir command parameters in linux"!

The following is how to use the dir command parameter in linux.

Dir command parameter function in linux:

The command formats supported by the dir command parameters in linux are:

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

Dir command parameters in linux are not case-sensitive and support multiple parameters.

The following parameters are mainly supported:

/ ON sorts by name

/ OE sorts by extension

/ OS sorts by size

/ OD is sorted by modification time

/ S display subdirectory file

/ W is in wide list format

The idea of dir command parameters in 1.linux is: through the judgment of each parameter, the corresponding command string (var) in DOS is constructed and run.

two。 Since it is impossible to determine how many parameters the command has in advance, use the shift statement to move the parameter to the left, judge the case of the $1 parameter through the case statement, and add the corresponding command parameter under bash to the end of the command string to be run.

3. What needs extra processing is that the dir command parameter in linux corresponds to ls-a-l, while dir / w corresponds to ls-a-m. This is done by processing the existence of "/ w" or "/ W" in $* by recording the number of times "/ w" or "/ W" appear. If * is 0, the initial value of the command string to be run is ls-a-l, otherwise it is ls-a-m. The case of other parameters is then processed (through 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 by"

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

ITunes 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

At this point, I believe you have a deeper understanding of "the application of dir command parameters in linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Parameters commands sorting applications characters strings methods statements processing support running content size situation format times learning practical deeper code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology Shulou Tech Info Xiaomi MySQL