Using Linux Wildcard Characters to See Linux Directories and Files – Linux System Admin Training

linux32 Using Linux Wildcard Characters to See Linux Directories and Files   Linux System Admin Training
Clyde E. Boom asked:




Linux Wildcard Characters in the [pattern] Part of a Linux Command

Wildcard characters are used in a Linux [pattern] to cause a command to work on multiple items and they represent characters in a pattern.

An * (asterisk) is used in a [pattern] to represent “all characters” in an item (when used alone) and “all other characters” in an item (when used with other characters, such as letters and numbers).

A ? (question mark) is used in a [pattern] to represent a single character. Multiple question marks can be used in a pattern to represent multiple characters, one character per question mark.

Linux ls Command Examples of Using Wildcard Characters

Run these Linux commands examples on your system to get real, practical training experience!

The Linux commands below likely will work will your Linux distribution, but if there is not output from the command, just read the description and carry on with the next command.

List all Linux files beginning with “l” in the directory path of /bin:

$ ls -l /bin/l*

List all files that contain the letters “rm” anywhere in the filename in the sbin directory:

$ ls -l /sbin/*rm*

List all files beginning with the letters e, f, g and h in the sbin directory:

$ ls -l /sbin/[e-h]*

Follow the concept of the Linux command examples above and use the wildcard patterns shown in the table below and run some more Linux commands!

Table of Linux Wildcard Character Examples

The Linux wildcard characters table below is extremely useful!

It shows lots of different ways of using wildcard characters with Linux commands.

The following are examples of using Linux wildcard characters in the [pattern] part of a command.

In the descriptions below, the word “items” is used to represent “directories and files”.

* all items (directories and files) – with or without a suffix
r* items beginning with the letter “r”
boot* items beginning with “boot”
*mem* items contain “mem” anywhere in the name
*.png items having the suffix of “.png” – that end in “.png” examples: app1.png and hello.png
?.cfg items starting with only one character and ending in “.cfg” examples: b.cfg and 3.cfg
memo?.sxw items beginning with “memo”, having a single character after “memo”, and having the suffix of “.sxw” Examples: memo1.sxw and memoh.sxw – not memo23.sxw
memo??.sxw items beginning with “memo”, having a two characters (only) after “memo”, and having the suffix of “.sxw” Examples: memo21.sxw and memok9.sxw – not memos.sxw
[a-z]* items that begin with any lower case letter and end in any other characters
[A-Z]-list.dat items that begin with any upper case letter and end in “-list.dat”
[a-zA-Z]report.sxc items that begin with any lower case or upper case letter and end in “report.sxc”
[c-f]* items that begin with the letters “c” through “f”
[Bb]ackup items that begin with “B” or “b” and end in “ackup”
jan[0-9] items that begin with “jan” and end in a number from 0 to 9
letters[3-7] items that begin with “letters” and end in a number from 3 to 7

The Linux commands and concepts covered here apply to: Debian, Red Hat, Fedora, Ubuntu, SUSE, Slackware, openSUSE – and ALL other Linux distributions.

Caffeinated Content

Related Posts

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark
tabs-top


No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment