Understanding “ls -l *.c” command in Linux

Akintola Mayode
5 min readAug 25, 2021

--

Linux is a free and open-source operating system first developed by Linus Torvalds and friends that was first announced August 25, 1991. The Linux kernel runs on numerous different platforms including the Intel and Alpha platform and is available under the GNU General Public License.

Now that we know what Linux is, let’s understand what a Shell Is

A shell is a program that reads commands that are typed on a keyboard and then executes (i.e., runs) them. Shells are the most basic method for a user to interact with the system. Every Unix-like operating system has at least one shell, and most have several. The default shell on most Linux systems is bash.

What is a command?

A command is an instruction given by a user telling the computer to do something, such as run a single program or a group of linked programs. Commands are generally invoked by typing them in at the command line (i.e., the all-text display mode) and then pressing the ENTER key, which pushes them to the shell. The general syntax for commands is:

command [options] [arguments]

What is the “ls” command?

The “ls” command is a command-line utility for listing the contents of a directory or directories via standard input. It writes results to standard output.

How ls -l works

The output from ls -l summarizes all the most important information about the file on one line. If the specified pathname is a directory, ls displays information on every file in that directory (one file per line). It precedes this list with a status line that indicates the total number of file system blocks (512 byte units) occupied by the files in that directory. Here is a sample of the output along with an explanation.

-rw-rw-rw- 1 root. dir 104 Dec 25 19:32 file

  • The first character identifies the file type:

- Regular file

  • The next nine characters are in three groups of three; they describe the permissions on the file. The first group of three describes owner permissions; the second describes group permissions; the third describes other (or world) permissions. Because Windows systems do not support group and other permissions, these are copies of the owner’s permissions. Characters that may appear are:

r. Permission to read file

w. Permission to write to file

x. Permission to execute file

  • After the permissions comes the number of links to the file.
  • Next comes the name of the owner of the file or directory. On file systems that don’t support 2012/8.1/2012R2/10/2016/2019 security, the owner name cannot be determined and the owner ID number is displayed instead. Under 2012/8.1/2012R2/10/2016/2019 the name of the owner of a file is displayed if the file’s SIDs can be obtained and if these SIDs have an associated name in the SAM database. If the file has a SID associated with it, but the name of the SID cannot be determined, then the value of the SID is displayed. (This can happen when the current user is not in the domain that was used when the file was created.) If the file does not have a SID (for example, if it is on a non-NTFS file system), or if the file security information cannot be accessed because the file is locked by another process, then the user name appears as <unavail>.

Note:

When a listed file is owned by the local computer, the owner is displayed as computer_name\ where computer_name is the name of the local computer.

  • Then comes the name of the group that owns the file or directory. On Windows systems, the same rules are followed for the group name as for the owner name.
  • Following this is the size of the file, expressed in bytes.
  • After this comes a date and time. For a file, this is the time that the file was last changed; for a directory, it is the time that the directory was created. The -c and -u options can change which time value is used. If the date is more than six months old or if the date is in the future, the year is shown instead of the time.
  • The last item on the line is the name of the file or directory.

What are wildcards and how to use them with “ls” command

A wildcard is a character that can be used as a substitute for any of a class of characters in a search, which increases the flexibility and efficiency of the search.

Wildcards are commonly used in shell commands in Linux and other Unix-like operating systems.

The most frequently employed and usually the most useful is the star wildcard, which is the same as an asterisk (*). The star wildcard has the broadest meaning of any of the wildcards, as it can represent zero characters, all single characters or any string.

Wildcards can be combined with other characters to represent parts of strings. For example, to represent any filesystem object that has a .jpg filename extension, *.jpg would be used.

How ls -l *.c works

It lists all the files with .c extension in the current working directory in a long format. ls displays information on every file with .c extension in that directory (one file per line). Below is an example of how ls -l *.c works

As you can see from the above image, writing the list command with the wildcard asterisk (*) to find all files ending with .c results in the output as listing all files that have the .c extension in a long format indicating the type of files, file permission, number of links to the files, the owner of the file/directory, name of the group that owns the file/directory, size of the file, date and time and lastly is the name of the file/directory.

Author:

Akintola Mayode and Nmesoma Solomon Peter

--

--