On ‘ls’ in Unix

In Unix and Unix-like operating systems, ls is a command to list files . When entered without any arguments, ls lists all the files in the current working directory. For more details, open the manual page for ‘ls’ command,

enter man ls

Now, suppose, you only want to see particular files and not all files. ls can list those too with the right arguement. For instance, if you want to list .c files in the current working directory, using

ls *.c

will print all the .c files. The ‘*’ is a wildcard character, which is used for expansion where the given command(here ‘ls’) never sees the wildcard, only the result of the expansion. Basically, this wildcard tries to match the argument, (here ‘.c’)and replaces it by the name of each & every file with that extension and then ls prints the name of those found files.

Lets try with an example,

If the directory is empty, ls prints nothing. Now, create two empty files with touch command. On doing ls again, it lists these files. If you do, ls . c, it throws error. On the right command, it prints .c file.