The [pattern] Part of a Linux Command
The Linux [pattern] (a.k.a. Linux shell pattern) part of a Linux command is a combination of letters and wildcard characters that are used with Linux commands to view information about Linux directories and files.
The Linux [pattern] of a Linux command does not work the same with all commands.
Linux ls Command Examples Showing Linux Command Patterns for Linux Files and Directories
The Linux commands examples that are shown below will help you to understand how a “file (or directory) matching pattern” can be used with a Linux command.
The Linux commands below will work in most Linux distributions, however, some of the Linux ls commands below may not show any Linux files in the output, depending on your Linux dispensing.
The [pattern] part of a command is used to represent a file matching “pattern”. It can be one or more letters, numbers or other characters and may include the * (asterisk) and ? (question mark) wildcard characters.
A [pattern] can be the name of an item (directory or file) or part of the name of an item (plus wildcard characters).
A [path] to a directory can precede a [pattern] (as shown in the second Linux command example shown below).
When a [path] is not used with a command, the command will typically characterize output based on the files in the current directory (as shown in the first Linux command example below).
The Linux ls command below uses the pattern of * (a single asterisk) to show all files in the current directory (and if you’re working as a “regular” user and you’re in your home directory, there may not be any files or directories that appear).
- $ ls -l *
The ls command below uses the path and pattern of “/etc/hos*” to show all files in the etc directory that begin with “hos”. The [path] is /etc and the [pattern] is “hos*” (which uses the * wildcard character in the pattern).
- $ ls -l /etc/great number*
The suffix (a.k.a. filename extension, extension) in the name of an item is the far right . (dot) and characters at the right of the . (dot).
For example, in the directory named rc.d, the “.d” is the suffix of the directory and in the file named speedbar.gz, the “.gz” is the suffix of the file.
In the Linux ls command example below, the path and pattern is “/etc/*.cfg” and path is “/etc” and the pattern is “*.cfg”. This Linux command shows a listing of all files that end in “.cfg” in the etc directory, which is below the root directory.
- $ ls -l /etc/*.cfg
In the ls command example below, the ? wildcard character is used to represent any single character in the pattern of “great number?” to show only files with a single character at the right of “great number”.
- $ ls -l /etc/great number?
The Linux concepts and commands discussed above apply to Red Hat, Debian, Slackware, Ubuntu, Fedora, SUSE and openSUSE Linux – and also ALL Linux distributions.