Implementation of Linux command line wildcards and escape characters

Implementation of Linux command line wildcards and escape characters

If we want to perform batch operations on a type of files, such as batch viewing of hard disk file attributes, 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 partition

Wildcards

An asterisk (*) matches zero or more characters.

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

The question mark (?) matches a single character.

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

The numbers [0-9] in the brackets match a single digit between 0 and 9, while the letters [abc] in the brackets match any one of the three characters a, b, and c.

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

View all device files starting with sda:

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

Check the device file with a character after sda:

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

Check the device file containing 0-9 numbers after sda:

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

Check the device file with 1, 3 or 5 after sda:

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

Escape Character

Backslash (\): turns a variable following the backslash into a simple string

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

Backquotes (``): execute the command and return the result

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 $ sign representing the variable value, an error is reported:

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

Add a backslash to escape the first $ sign:

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

Using single quotes, the variable will no longer be evaluated:

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

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

[root@linuxprobe ~]# echo `uname -a`
Linux linuxprobe.com 3.10.0-123.el7.x86_64 #1 SMP Mon May 5 11:16:57 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of Linux shell command line options and parameters
  • Linux command line and shell scripting Richard Blum
  • Detailed explanation of commonly used shortcut keys for Linux terminal command line
  • Detailed explanation of Linux shell command line parameters usage

<<:  How to solve the 2002 error when installing MySQL database on Alibaba Cloud

>>:  Detailed explanation of vite2.0+vue3 mobile project

Recommend

Detailed explanation of Vue's caching method example

Recently, a new requirement "front-end cache...

Vue Element-ui implements tree control node adding icon detailed explanation

Table of contents 1. Rendering 2. Bind data and a...

Method of using MySQL system database for performance load diagnosis

A master once said that you should know the datab...

Ideas and methods for incremental backup of MySQL database

To perform incremental backup of the MySQL databa...

MySql Installer 8.0.18 Visual Installation Tutorial with Pictures and Text

Table of contents 1. MySQL 8.0.18 installation 2....

JavaScript implements simple date effects

The specific code of JavaScript date effects is f...

ftp remotely connect to Linux via SSH

First install ssh in Linux, taking centos as an e...

Search engine free collection of website entrances

1: Baidu website login entrance Website: http://ww...

Issues with using Azure Container Registry to store images

Azure Container Registry is a managed, dedicated ...

How to use docker compose to build fastDFS file server

The previous article introduced a detailed exampl...

A brief discussion on the Linux kernel's support for floating-point operations

Currently, most CPUs support floating-point units...

How to configure ssh to log in to Linux using git bash

1. First, generate the public key and private key...

How to solve the DOS window garbled problem in MySQL

The garbled code problem is as follows: The reaso...

Summary of 4 methods of div+css layout to achieve 2-end alignment of css

The div+css layout to achieve 2-end alignment is ...