6 Linux metacharacters I love using on the command line
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
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

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

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

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$

插入符号^
^
符号将结果限制为以给定字符串开头的项。例如,当同时使用元字符 |
和^
时:
linuxmi@linuxmi /home/linuxmi/www.linuxmi.com ⚡ ls | grep ^linuxmi

其中许多元字符是通向正则表达式的入口,因此还有很多东西需要探索。请问下你最熟悉的 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.
