Using the Linux Ls Command to See Linux File "Patterns" – Linux Commands Training Quick Tips

[ad_1]

The [pattern] Part of a Linux Command

The Linux [pattern] (aka 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 distribution.

The [pattern] component 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 display 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 / host *

The suffix (aka 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 "host?" to show only files with a single character at the right of "host".

    $ Ls -l / etc / host?

The Linux concepts and commands discussed above apply to Red Hat, Debian, Slackware, Ubuntu, Fedora, SUSE and openSUSE Linux – and also ALL Linux distributions.

[ad_2]

Source by Clyde E. Boom

Leave a Reply

Your email address will not be published. Required fields are marked *