Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the meaning of Linux midpoint?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the meaning of Linux midpoint, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Paul Brown explains the various meanings and uses of the obscure "dot" in the Linux shell command.

In the real world, a single-line command or script written with the shell command can be confusing. The names of many of the tools you use are a far cry from their actual functionality (grep, tee, and awk, is there any more? ), and when you combine two or more, the "sentence" looks more like some kind of alien book.

Therefore, the above does not help you, because the symbols you use to write a series of instructions have different meanings depending on the scenario you use.

Position, position, position

Take this humble dot (.) for example. When it is placed at the argument of a command that requires a directory name, it means "current directory":

Find. -name "* .jpg"

Look for files ending in .jpg in the current directory (including subdirectories).

Ls. And cd. As you might expect, they enumerate and "enter" the current directory respectively, although this point is superfluous in both cases.

The two dots followed by the other represent "the parent directory of the current directory" in the same scenario (that is, when your command expects a file directory). If you are currently under / home/your_directory and running:

Cd..

You will enter / home. So, you might think that this is still appropriate for the "dot represents nearby catalog" narrative, and it's not complicated, right?

So what happens down there? If you add a dot to the beginning of a file or directory, it indicates that the file or directory will be hidden:

$touch somedir/file01.txt somedir/file02.txt somedir/.secretfile.txt$ ls-l somedir/total 0 paul paul Jan 13 19:57. Drwx-48 paul paul 4096 Jan 13 19:57 file01.txt-rw-r--r-- 1 paul paul 0 Jan 13 19:57 file02.txt$ # Note that there is no .secretfile.txt $ls-la somedir/total 8drwxr-xr-x 2 paul paul 4096 Jan 13 19:57 in the above listing. 19:57.-rw-r--r-- 1 paul paul 0 Jan 13 19:57 file01.txt-rw-r--r-- 1 paul paul 0 Jan 13 19:57 file02.txt-rw-r--r-- 1 paul paul 0 Jan 13 19:57 .secretfile.txt $# this-an option tells ls to display the "all" file Including the hidden ones.

And then you can put. As an order. Yes, you listen to me:. It's a real order. It is synonymous with the source command, so you can use it to execute a file in the current shell instead of running a script file in some other way (this usually means that Bash generates a new shell to run it)

Confused? Don't worry-try this: create a script called myscript that contains the following line:

Myvar= "Hello"

Then execute it the usual way, that is, with sh myscript (or make it executable through the chmod axix myscript command, and then run. / myscript). Now try and observe the contents of myvar, via echo $myvar (of course you get nothing). That's because when your script assigns "Hello" to myvar, it's done in an isolated bash shell instance. When the script finishes, the newly generated instance disappears and transfers control to the original shell, which does not even have the myvar variable.

However, if you run myscript like this:

. Myscript

Echo $myvar will print the Hello to the command line.

When your .bashrc file changes, you often use the. (or source) command, just like when you want to extend the PATH variable. In your current shell instance, you can use. To make the change take effect immediately.

Double trouble

Just as a seemingly insignificant point has more than one meaning, so do two points. In addition to pointing to the parent of the current directory, two dots (..) are also used to build the sequence.

Try this:

Echo {1..10}

It prints a sequence from 1 to 10. In such a scene, Means "count from the value on the left to the value on the right".

Now try this:

Echo {1..10..2}

You'll get 1, 3, 5, 7, 9. . 2 this part of the command tells Bash to output the sequence, but not by 1 for each, but by 2. In other words, you will get an odd number from 1 to 10.

It still works the other way around:

Echo {10..1..2}

You can also fill your number with multiple zeros. Like this:

Echo {000..121..2}

Even numbers from 0 to 121 (filled with leading zeros) are printed like this:

000 002 004 006... 050 052 054... 116 118 120

But what is the use of such a sequence generator? Of course, suppose one of your New year's resolutions is to control your account spending more carefully. As part of your determination, you need to create a catalog to categorize digital invoices for the past 10 years:

Mkdir {2009..2019} _ Invoices

The work is done.

Or you may have hundreds of numbered files, such as frames extracted from a video clip, or for some reason you just want to delete one frame every three frames from frames 43 to 61:

Rm frame_ {043..61..3}

Most likely, if you have more than 100 frames, they will be named with padding 0, as follows:

Frame_000 frame_001 frame_002...

That's why you use 043 instead of 43 in your command.

Curly braces tricks

To be honest, the magic of the sequence is not the double dots, but the witchcraft of curly braces ({}). See how it works for letters. Do this:

Touch file_ {a..z} .txt

It creates files from file_a.txt to file_z.txt.

But you have to be careful. Using a sequence like {Z.. a} produces a large number of non-alphanumeric characters (neither numeric or alphanumeric) between uppercase and lowercase letters. Some of these glyphs are not printable or have their own special meaning. Using them to generate file names can lead to a series of unexpected and potentially unpleasant effects.

One thing worth pointing out: a sequence surrounded by {.}, they can also contain a list of strings:

Touch {blahg, splurg, mmmf} _ file.txt

Blahg_file.txt, splurg_file.txt, and mmmf_file.txt will be created.

Of course, in other scenarios, curly braces have different meanings (surprise! ). But that's the content of another article.

Thank you for reading this article carefully. I hope the article "what is the meaning of Linux midpoint" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report