Table of Contents
Shell metacharacters on Linux" >Shell metacharacters on Linux
Pipeline |" >Pipeline |
Output Redirection >" >Output Redirection >
Asterisk *" >Asterisk *
tilde~" >tilde~
Dollar sign $" >Dollar sign $
插入符号^" >插入符号^
Home System Tutorial LINUX 6 Linux metacharacters I love using on the command line

6 Linux metacharacters I love using on the command line

Feb 13, 2024 pm 12:30 PM
linux linux tutorial linux system linux command shell script embeddedlinux Getting started with linux linux learning

Early in my Linux journey, I learned how to use the command line. This is what makes Linux unique. I might lose the graphical user interface (GUI), but there's no need to completely rebuild the machine. Many Linux computers run in headless mode, allowing you to complete all administrative tasks on the command line. It uses many basic commands that everyone is familiar with, such as ls, ls-l, ls-l, cd, pwd, top, etc.

Shell metacharacters on Linux

You can expand each of these commands by using metacharacters. I don't know what you call them, but using metacharacters on the Linux command line is a great way to increase productivity.

Pipeline |

Suppose I want to know all instances of Firefox running on my system. I can use the ps command with -ef to list all instances of a program running on my system. Now I want to look at those instances involving Firefox. I use one of my favorite metacharacters, piping | to the grep program, which scans the entire file contents. means

ps

and grep commands are executed at the same time<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>linuxmi@linuxmi /home/linuxmi/www.linuxmi.com                               ⚡ ps -ef | grep firefox </pre><div class="contentsignin">Copy after login</div></div> <h2 style="margin-top: 30px;margin-bottom: 15px;padding: 0px;font-weight: bold;color: black;font-size: 22px;text-align: left;margin: 20px 10px 0px 0px"><span class="content" style="font-size: 18px;font-weight: bold;color: #222;display: inline-block;padding-left: 10px;border-left: 5px solid #f83929"><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/887/227/170779863019344.png" class="lazy" alt="我喜欢在命令行中使用的 6 个 Linux 元字符" /></span></h2> <h2 id="span-class-content-style-font-size-px-font-weight-bold-color-display-inline-block-padding-left-px-border-left-px-solid-f-Output-Redirection-span"><span class="content" style="font-size: 18px;font-weight: bold;color: #222;display: inline-block;padding-left: 10px;border-left: 5px solid #f83929">Output Redirection ></span></h2> <p>Another favorite metacharacter is output redirection <code style="font-size: 14px;padding: 2px 4px;border-radius: 4px;margin: 0 2px;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;color: #10f5d6c">>. I use it to display dmesg messages for the eth0 user interface using the grep option followed by eth0. The command results are saved to linuxmi.txt. You may find this useful.

linuxmi@linuxmi /home/linuxmi/www.linuxmi.com                              
⚡ sudo dmesg | grep -i eth0 > linuxmi.txt
[sudo] linuxmi 的密码: 

linuxmi@linuxmi /home/linuxmi/www.linuxmi.com                              
⚡ cat linuxmi.txt
[    3.647685] e1000 0000:02:01.0 eth0: (PCI:66MHz:32-bit) 00:0c:29:0e:a2:7c
[    3.647694] e1000 0000:02:01.0 eth0: Intel(R) PRO/1000 Network Connection
[    3.651280] e1000 0000:02:01.0 ens33: renamed from eth0
Copy after login
我喜欢在命令行中使用的 6 个 Linux 元字符

Asterisk *

The asterisk * or wildcard characters are preferred when looking for files with the same extension (such as .jpg or .png). I first enter the image directory in the system, and then use the following command:

linuxmi@linuxmi /home/linuxmi/www.linuxmi.com                              
⚡ ls *.png
linuxmi.com.png  www.linuxmi.com.png
Copy after login
我喜欢在命令行中使用的 6 个 Linux 元字符

tilde~

The tilde ~ is a quick way to return to the home directory of your Linux system by entering the following command:

linuxmi@linuxmi /home/linuxmi/www.linuxmi.com                              
⚡ cd ~

linuxmi@linuxmi /home/linuxmi                                              
⚡ pwd                  
/home/linuxmi
Copy after login
我喜欢在命令行中使用的 6 个 Linux 元字符

Dollar sign $

The $ symbol as a metacharacter has a different meaning. When used to match a pattern, it represents any string that ends with the given string. For example, when using the metacharacters | and $ together:

linuxmi@linuxmi /home/linuxmi/www.linuxmi.com                              
⚡ ls | grep png$
Copy after login
我喜欢在命令行中使用的 6 个 Linux 元字符

插入符号^

^ 符号将结果限制为以给定字符串开头的项。例如,当同时使用元字符 |^时:

linuxmi@linuxmi /home/linuxmi/www.linuxmi.com                              
⚡ ls | grep ^linuxmi
Copy after login
我喜欢在命令行中使用的 6 个 Linux 元字符

其中许多元字符是通向正则表达式的入口,因此还有很多东西需要探索。请问下你最熟悉的 Linux 元字符是什么,它们是如何拯救你的工作的?

相关文章:

  • 在 Linux 系统上使用更好的正则表达式 https://www.linuxmi.com/linux-regular-expression-grep.html
  • 5种使用正则表达式搜索纯文本数据的最佳命令行工具 https://www.linuxmi.com/5-regex-minglinghang.html

The above is the detailed content of 6 Linux metacharacters I love using on the command line. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

Four ways to implement multithreading in C language Four ways to implement multithreading in C language Apr 03, 2025 pm 03:00 PM

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

How to open web.xml How to open web.xml Apr 03, 2025 am 06:51 AM

To open a web.xml file, you can use the following methods: Use a text editor (such as Notepad or TextEdit) to edit commands using an integrated development environment (such as Eclipse or NetBeans) (Windows: notepad web.xml; Mac/Linux: open -a TextEdit web.xml)

Can the Python interpreter be deleted in Linux system? Can the Python interpreter be deleted in Linux system? Apr 02, 2025 am 07:00 AM

Regarding the problem of removing the Python interpreter that comes with Linux systems, many Linux distributions will preinstall the Python interpreter when installed, and it does not use the package manager...

What is the Linux best used for? What is the Linux best used for? Apr 03, 2025 am 12:11 AM

Linux is best used as server management, embedded systems and desktop environments. 1) In server management, Linux is used to host websites, databases, and applications, providing stability and reliability. 2) In embedded systems, Linux is widely used in smart home and automotive electronic systems because of its flexibility and stability. 3) In the desktop environment, Linux provides rich applications and efficient performance.

How is Debian Hadoop compatibility How is Debian Hadoop compatibility Apr 02, 2025 am 08:42 AM

DebianLinux is known for its stability and security and is widely used in server, development and desktop environments. While there is currently a lack of official instructions on direct compatibility with Debian and Hadoop, this article will guide you on how to deploy Hadoop on your Debian system. Debian system requirements: Before starting Hadoop configuration, please make sure that your Debian system meets the minimum operating requirements of Hadoop, which includes installing the necessary Java Runtime Environment (JRE) and Hadoop packages. Hadoop deployment steps: Download and unzip Hadoop: Download the Hadoop version you need from the official ApacheHadoop website and solve it

Is Debian Strings compatible with multiple browsers Is Debian Strings compatible with multiple browsers Apr 02, 2025 am 08:30 AM

"DebianStrings" is not a standard term, and its specific meaning is still unclear. This article cannot directly comment on its browser compatibility. However, if "DebianStrings" refers to a web application running on a Debian system, its browser compatibility depends on the technical architecture of the application itself. Most modern web applications are committed to cross-browser compatibility. This relies on following web standards and using well-compatible front-end technologies (such as HTML, CSS, JavaScript) and back-end technologies (such as PHP, Python, Node.js, etc.). To ensure that the application is compatible with multiple browsers, developers often need to conduct cross-browser testing and use responsiveness

Do I need to install an Oracle client when connecting to an Oracle database using Go? Do I need to install an Oracle client when connecting to an Oracle database using Go? Apr 02, 2025 pm 03:48 PM

Do I need to install an Oracle client when connecting to an Oracle database using Go? When developing in Go, connecting to Oracle databases is a common requirement...

See all articles