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

How to implement command line wildcards in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

In this issue, the editor will bring you about how to achieve command line wildcards in Linux. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

If we want to perform batch operations on a class of files, such as batch viewing the attributes of hard disk files, the normal command would be:

[root@linuxprobe ~] # ls / dev/sda [root@linuxprobe ~] # ls / dev/sda1 [root@linuxprobe ~] # ls / dev/sda2 [root@linuxprobe ~] # ls / dev/sda3

But sometimes I really don't know the zoning.

Wildcard character

The asterisk (*) represents a match of zero or more characters

Huanyu@ubuntu:~$ ls-l / dev/sda*

The question mark (?) means to match a single character

Huanyu@ubuntu:~$ ls-l / dev/sda?

The number [0-9] in square brackets represents a character that matches a single number between 0,9, while the letter [abc] in square brackets represents any of the three characters matching a, b, and c.

Huanyu@ubuntu:~$ ls-l / dev/sda [0-9] huanyu@ubuntu:~$ ls-l / dev/sda [135]

Example:

View all device files at the beginning of sda:

[root@linuxprobe ~] # ls / dev/sda*/dev/sda / dev/sda1 / dev/sda2

Look at the device file with one character after sda:

[root@linuxprobe ~] # ls / dev/sda?/dev/sda1 / dev/sda2

View the device file that contains the 0-9 number after the sda:

[root@linuxprobe] # ls / dev/sda [0-9] / dev/sda1 / dev/sda2

Look at the device files followed by 1 or 3 or 5 after sda:

[root@linuxprobe] # ls / dev/sda / dev/sda1

Escape character

Backslash (\): changes a variable after a backslash to a simple string

Huanyu@ubuntu:~$ echo "Price is\ $$PRICE"

Reverse quotation mark (``): returns the result after executing the command

Huanyu@ubuntu:~$ echo `uname-a`

Example

Define a variable named PRICE with a value of 5:

[root@linuxprobe ~] # PRICE=5

To output "Price is 5":

[root@linuxprobe ~] # echo "Price is $PRICE" Price is 5

I want to output "the price is $5", but because the dollar sign conflicts with the $symbol that represents the value of the variable, it is reported incorrectly:

[root@linuxprobe ~] # echo "Price is $$PRICE" Price is 3767PRICE

Add a backslash to escape the first $symbol:

[root@linuxprobe ~] # echo "Price is\ $PRICE" Price is $5

Using single quotation marks, the variable will no longer be valued:

[root@linuxprobe ~] # echo 'Price is\ $PRICE'Price is\ $PRICE

After executing uname-a, you can view the version and architecture information of the native kernel (the commands in backquotes will be executed):

[root@linuxprobe ~] # echo `Linux-a`Linux linuxprobe.com 3.10.0-123.el7.x86_64 # 1 SMP Mon May 5 11:16:57 EDT 2014 x86 "64 x 86" 64 GNU/Linux what is Linux system Linux is a free use and free dissemination of UNIX-like operating system, is a POSIX-based multi-user, multi-tasking, multi-threading and multi-CPU operating system Using Linux, you can run major Unix tools, applications, and network protocols.

The above is the editor for you to share how to achieve command-line wildcards in Linux, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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