Early in my Linux journey, I learned how to use the command line. It's what sets Linux apart. I could lose the graphical user interface (GUI), but it was unnecessary to rebuild the machine completely. Many Linux computers run headless, and you can accomplish all the administrative tasks on the command line. It uses many basic commands that all are familiar with—like
top, and many more.
Shell metacharacters on Linux
You can extend each of those commands through the use of metacharacters. I didn't know what you called them, but metacharacters have made my life easier.
Say that I want to know all the instances of Firefox running on my system. I can use the
ps command with an
-ef to list all instances of the programs running on my system. Now I'd like to see just those instances where Firefox is involved. I use one of my favorite metacharacters, the pipe
| the result to
grep, which searches for patterns.
$ ps -ef | grep firefox
Output redirection >
Another favorite metacharacter is the output redirection
>. I use it to print the results of all the instances that Intel mentioned as a result of a
dmesg command. You may find this helpful in hardware troubleshooting.
$ dmesg | grep amd > amd.txt $ cat amd.txt [ 0.897] amd_uncore: 4 amd_df counters detected [ 0.897] amd_uncore: 6 amd_l3 counters detected [ 0.898] perf/amd_iommu: Detected AMD IOMMU #0 (2 banks, 4 counters/bank).
* or wildcard is a favorite when looking for files with the same extension—like
.png. I first change into the
Picture directory on my system and use a command like the following:
$ ls *.png BlountScreenPicture.png DisplaySettings.png EbookStats.png StrategicPlanMenu.png Screenshot from 01-24 19-35-05.png
~ is a quick way to get back to your home directory on a Linux system by entering the following command:
$ cd ~ $ pwd /home/don
Dollar symbol $
$ symbol as a metacharacter has different meanings. When used to match patterns, it means any string that ends with a given string. For example, when using both metacharacters
$ ls | grep png$ BlountScreenPicture.png DisplaySettings.png EbookStats.png StrategicPlanMenu.png Screenshot from 01-24 19-35-05.png
^ symbol restricts results to items that start with a given string. For example, when using both metacharacters
$ ls | grep ^Screen Screenshot from 01-24 19-35-05.png
Many of these metacharacters are a gateway to regular expressions, so there's a lot more to explore. What are your favorite Linux metacharacters, and how are they saving your work?