Using the Linux Ls Command to List File Names by File Suffix – Linux Commands Training Quick Tips

0
5

A Linux "file name suffix" (aka filename suffix) is the dot "something" at the end of a filename, such as .txt (dot txt) and .conf (dot conf).

A Linux file suffix can be one or more characters. Such as .o (one character), .so (two characters) and .cfg (three characters) and a file suffix can even have another. (dot) followed by more characters, such as: .2.gz .

Some Linux file names show the "type" of file, such as .txt for text files and .conf for Linux server and system configuration files.

Also, many Linux file names do not have file name suffixes.

For example, many Linux command program files, sometimes called "binaries", such as the ls command binary – and the program files for many other Linux commands – do not have a file name suffix.

Linux ls Command Examples Viewing Various File Types for Multiple Files

The * (asterisk) in the Linux ls command examples below is being used to represent "anything" in the file name at the left of the file name suffix.

For example, * .conf is used with the Linux ls command (and other commands) to get a listing of files with any text in the name at the left of the .conf .

Linux Commands Training Tips: When an * (asterisk) is used with a Linux command, this is called a wildcard character and this can also be used with other commands to show information on Linux files and directories. And the other wildcard character is the? (question mark) and these can be used in other ways.

The Linux commands below will work in most Linux distributions, however, some of the ls commands below may not show any Linux files in the output, depending on your distribution.

The Linux ls command example below shows the (very important) Linux system and server conf iguration files in the etc directory ending in. conf .

    $ ls -l /etc/*.conf

Now list some of the Linux man page files ending in .gz.

    $ ls -l /usr/share/man/man1/*.gz

Remember that you can edit a previous command by pressing the up arrow key

Press the up arrow key and change the above command (with the file pattern of * .gz) to be the command below (with * ..gz) and run it.

    $ ls -l /usr/share/man/man1/*.1.gz

This shows files that have a filename suffix with two dots.

Now list the inittab file to see that it does not contain a file name suffix.

    $ ls -l / etc / inittab

The Linux ls command example below shows that the ls binary (command program file) does not have a file name suffix either.

    $ ls -l / bin / ls

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

Source

Leave a Reply