Unix Shell Commands

A shell command is usually in the following format:
command options arguments
Options are specified with a preceding - sign. Arguments can be any character strings. For example, consider the following command:
ls -l mydir
ls is the 'list' command to list files. The option -l, tells ls that, the files must be listed in long format. Mydir is the argument, which is the name of the folder to be listed. There can be multiple arguments for a command separated by spaces.
ls -l mydir1 mydir2
The above command tells ls that files in both folders mydir1 and mydir2 must be listed.

Meta Characters

Meta characters are characters with special meaning. They are useful for inexact searches. For example, if you need to list all files beginning with the letter a, you can use the following command:

ls a*
*-here represents, zero or more characters.

If you are not sure about a single character, you may use the meta character ? to represent that character as below:

ls file?
The above command will list the following files, if present in the folder: file1, file2, files (but will not list file, why?).

Input/Output Redirection

Although normally Unix® takes input from the keyboard and displays the output on the screen, it can read from a file and write to a file very easily. All you need to do is to use redirection symbols (< and >).

For example, if you want the output of the ls to go to a file called listing.txt, you may type:

ls >listing.txt


Unix® files may be concatenated using cat command. cat file1 file2 will concatenate the two files and display the results on the standard output (usually screen). Just a note that if the input or output are not explicitly specified, they are assumed as standard input (usually keyboard) or standard output. As you might have already imagined, cat file will just display the file (there is nothing to concatenate here). So, if you just type cat, what will happen?

Exercise: Redirect the listing of a directory to a file named listing.txt, and then display the file using cat.


In Unix®, you can get help on a command by using man. If you want to know how to use man command, try man man. Don't you think that was very logical? Exercise: Read man pages of the commands, ls, and cat.

Note on Unix® files and directories

In Unix®, almost everything is accessible as files. For instance, you can access your printer as a file. If you want to print something, redirect the output to the corresponding device file. Even directories in Unix® are special kinds of files.

Next: Unix® File System

You may share this article on Facebook.