• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result

Everything you need to know about Linux metacharacters

AnonyViet by AnonyViet
December 29, 2023
in Network
0

The most powerful feature of the Linux Bash shell is its ability to work with files and redirect their input and output extremely efficiently. Linux uses special characters or symbols called metacharacters that complement shell commands related to file searches and command connections.

Join the channel Telegram belong to AnonyViet 👉 Link 👈

Everything you need to know about Linux metacharacters

Superscripts are useful in listing, deleting, and copying files on Linux. However, the function of each superscript differs depending on the command you are using.

This article provides an in-depth understanding of the different types of superscripts in Linux. And I will explain how these special characters help connect and expand commands.

Handle files with superscripts

The Linux shell allows you to save keystrokes when entering commands by using superscripts between file or directory names. These characters help you refer to a group of files or a folder to list, move, or perform other actions.

Here are some superscripts in the Linux Shell:

  • * (Asterisk): Matches one or more occurrences of a character
  • ? (Question mark): Matches a single character or a pattern occurrence
  • [] (Square brackets): Match any numbers, symbols, or hyphen-separated alphabets specified inside square brackets

An ideal way to practice superscript in Linux is to create a new empty folder inside the folder /tmp.

sudo mkdir /tmp/meta

Now access the folder /tmp/meta by command CD and create new empty files using command touch:

touch apple.txt cider.sh vinegar.php cat.txt lemon.txt juice.sh catfish.sh

Use the following commands to test the super character “*” and display the output:

ls c*
Output:
catfish.sh cat.txt cider.sh
ls c*h
Output:
catfish.sh cider.sh
ls *r*
Output:
cider.sh vinegar.php
sudo rm *p*

The above command will delete all files containing the character “p” in its name. You can confirm the change with the command ls:

ls
Output:
catfish.sh cat.txt cider.sh juice.sh lemon.txt

Here are some examples of the “?” sign:

ls a?*
Output:
apple.txt
ls c?t*
Output:
catfish.sh cat.txt

The last command matches any file that begins with a letter c and there are words t is the third letter (cat.txt, catfish.sh,…). Now use options [av]* with ls command to list all files starting with a or v:

ls [av]*
Output:
apple.txt vinegar.sh

You can modify the above command to list only files that end with letters t:

ls [ac]*[t]
Output:
apple.txt catfish.txt cat.txt

Similarly, you can use letters separated by hyphens to scope and list files like this:

ls [a-j]*
Output:
apple.txt catfish.sh cat.txt cider.sh juice.sh

Superscript file redirection

To better understand redirection in Bash, every process in Linux has file descriptors, called standard input (stdin/0), standard output (stdout/1), and standard error ( stderr/2). They determine the origin of command input and decide where to send output and error messages.

Superscripts help you modify these actions by I/O content stream redirection. In general, the Linux shell reads command input from the keyboard and writes the results to the screen. Input redirection allows the command to read content from a file instead of the keyboard, and output redirection saves the output to the file.

In other words, the Linux file redirection superscript allows you to redirect content to (>) and from (<) files. The three main navigation superscripts are:

first. <: Convert file content to command. For example: command output for less .bashrc like less < .bashrc.

2. >: Pipe command output to file. Command ls /etc > lists.txt will save the output to file lists.txt.

3. >>: Add command output to file content.

Everything you need to know about Linux 7 metacharacters

wc stands for word count and you can use it to show the difference between the file before and after attaching it to the output.

The superscript expands curly braces

The curly brace expansion metacharacter allows you to expand characters across directories, filenames, or other command parameters. For example, you can create a new folder inside the folder /tmp and create a set of files using the touch command as follows:

sudo mkdir /tmp/brace; cd /tmp/brace
touch test{1,2,3,4,5}

Now you can check whether touch has created the file or not using the ls command.

ls
Output:
test1 test2 test3 test4 test5

You can specify multiple lists to generate file names based on a combination of elements in the list. For example:

touch {apple,cider,vinegar}.{fruit,liquid,sour}
touch {a,b,c}.{1,2,3}

The last command will create the following files in the current directory:

Everything you need to know about Linux 8 metacharacters

The first command uses two sets of curly braces to link the filenames in each set to the other. You can also write the final command by touch {a..c}. {1..3} to specify the range between a and c and 1 and 3.

In addition to creating files, you can also use curly braces to delete or copy files to other locations.

Some other Linux superscripts

Below is a table of some superscripts you must know to connect commands with their names, descriptions and examples for practice:

Name Describe For example
Pipe (|) Connect command output as input to another command. cat /etc/passwd | grep root
Semicolon (;) Allows executing commands sequentially, one after another. cd /etc ; ls -la ; chmod +x /tmp/script.php
Ampersand (&) Run processes or commands in the background. find / -perm -u=s -type f &
Dollar ($) Expand the arithmetic expression and pass it to the shell echo “total files in this directory are: $(ls | wc -l)”
Null Redirection (2>) Direct standard error messages to the file /dev/null your_command 2>/dev/null
Circumflex (^) Matches any pattern that begins with an expression followed by ^ cd /etc/ssh ; ls | grep ^s

Supercharacters on Linux are also known as wildcards that add special meaning to commands and control their behavior. Superscripts optimize user's work performance while working with files/folders and connecting/extending Linux shell commands.

Besides, superscripts are also the building blocks of regular expressions. Additionally, learning about superscripts and how to use them is an important skill to have if you want to become a professional Linux user.

Additionally, you can also see how to write Shell Script in Linux here.

The article scored: 5/5 – (100 votes)

Tags: Linuxmetacharacters
Previous Post

7 little-known Gmail features you should try

Next Post

The simplest way to change the Theme for Chrome browser

AnonyViet

AnonyViet

Related Posts

Script backup database and website on telegram
Network

Script backup database and website on telegram

May 2, 2025
Create 64GB RAM 16 core for free on Google IDX
Network

Create 64GB RAM 16 core for free on Google IDX

April 13, 2025
What is VPS running Vietnamese software? What is the reason for installing Vietnamese software on VPS?
Network

What is VPS running Vietnamese software? What is the reason for installing Vietnamese software on VPS?

February 17, 2025
Create Ronin wallet to play pixels on VPS Windows
Network

Create Ronin wallet to play pixels on VPS Windows

February 17, 2025
What is Proxy Gradient Network? Instructions for using Proxy to suspend multiple Gradient accounts
Network

What is Proxy Gradient Network? Instructions for using Proxy to suspend multiple Gradient accounts

December 26, 2024
How to buy a .news domain for free for 0 VND at Namecheap
Network

How to buy a .news domain for free for 0 VND at Namecheap

December 22, 2024
Next Post
The simplest way to change the Theme for Chrome browser

The simplest way to change the Theme for Chrome browser

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

Discover Supermix – Smart playlist on YouTube Music

Discover Supermix – Smart playlist on YouTube Music

May 20, 2025
The 10 best Torrent websites today – 100% still operate

The 10 best Torrent websites today – 100% still operate

May 20, 2025
Share Code Shop Selling Acc game extremely lightweight written in bootstrap

Share Code Shop Selling Acc game extremely lightweight written in bootstrap

May 19, 2025
Instructions for downloading all photos and story from Instagram

Instructions for downloading all photos and story from Instagram

May 19, 2025
Discover Supermix – Smart playlist on YouTube Music

Discover Supermix – Smart playlist on YouTube Music

May 20, 2025
The 10 best Torrent websites today – 100% still operate

The 10 best Torrent websites today – 100% still operate

May 20, 2025
Share Code Shop Selling Acc game extremely lightweight written in bootstrap

Share Code Shop Selling Acc game extremely lightweight written in bootstrap

May 19, 2025
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

Discover Supermix – Smart playlist on YouTube Music

Discover Supermix – Smart playlist on YouTube Music

May 20, 2025
The 10 best Torrent websites today – 100% still operate

The 10 best Torrent websites today – 100% still operate

May 20, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí SHBET bongdaso

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí SHBET bongdaso