LFCS — Linux Foundation Certified Systems Administration Preparatory Course by Emmanuel Odenyire
Lesson 3 — Using Essential File Management Tools
Topic: Using shell wildcards
Introduction
Shell wildcards, also known as “globbing patterns,” are special characters used to represent one or more characters in a filename or directory name. Wildcards allow you to perform operations on multiple files at once, such as copying, moving, or deleting them. In this topic, we will discuss some commonly used shell wildcards in Ubuntu.
Asterisk ():- The asterisk () is the most commonly used wildcard character. It represents any sequence of characters (including zero characters) in a filename. For example, to list all files with a “.txt” extension in the current directory, you can use the following command:
$ ls *.txt
This will list all files in the current directory that have a “.txt” extension.
Question mark (?):- The question mark (?) is another commonly used wildcard character. It represents any single character in a filename. For example, to list all files that have a three-letter extension in the current directory, you can use the following command:
$ ls ???.*
This will list all files in the current directory that have a three-letter extension.
Bracketed characters ([ ]):- Brackets can be used to specify a range of characters or a set of characters to match. For example, to list all files with an extension of “.txt” or “.pdf” in the current directory, you can use the following command:
$ ls *.[tp][df]
This will list all files in the current directory that have an extension of either “.txt” or “.pdf”.
Negation (!):- The negation (!) can be used to exclude files that match a certain pattern. For example, to list all files in the current directory except those with a “.txt” extension, you can use the following command:
$ ls !(*.txt)
This will list all files in the current directory except those with a “.txt” extension.
References:
For more information on shell wildcards in Ubuntu, you can check out the Ubuntu documentation on wildcards (https://help.ubuntu.com/community/UsingTheTerminal#Wildcards_and_File_Manipulation), as well as the Bash manual page on shell patterns (https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html).
Linux Shell Scripting Tutorial: https://bash.cyberciti.biz/guide/Shell_Globbing
Ubuntu Documentation: https://help.ubuntu.com/community/UsingTheTerminal