Command Line Basics: Create Custom Commands with Alias
In today's Command Line Basics we'll create some customized commands with alias. You can think of alias as a sort of command line shortcut. Odds are, your system already has a few aliases defined by default. If you enter the command by it's self, without an argument, it will tell you what aliases already exist on your system. Open a terminal window and give it a try.
alias l='ls -CF'
alias la='ls -A'
alias ls='ls --color=auto'You may see some output that looks like the above. That output shows the proper syntax to create a new alias. One command I like to alias is 'ls -l'.
This functionality works great, but defining an alias on the fly only makes it stick to the current shell. If you open another terminal window, this alias won't be defined.
If you want an alias to be available every time you open a terminal window, you can define it in the .bashrc file. Go to your terminal and enter the following:
nano .bashrc
Now arrow down to an appropriate place in this file to define your alias. If you're not sure where to put it, the very bottom of the file should be fine. Now add a line to define an alias.
alias ll='ls -l'Save the file and exit the editor. The .bashrc file is read each time you start a new bash shell. To test your new file you can close the terminal window and open a new one, or force the current window to re-read the .bashrc file with:
Have an aliased command that you find particularly useful? Leave a comment.
Command Line Basics: List Files with ls
One of the most fundamental things you may want to do from the command line is to list the files in the current directory. That's where the ls command comes in. ls stands for, you guessed it, list.
Say, for example, you are in a directory that has three files in it called file1, file2, and file3. Entering ls on the command line will yield output that looks like:
file1 file2 file3A common option that is used with the ls command is the -l option. The -l option creates a long listing. The output from that would look like this:
-rw-r--r-- 1 owner group 0 2009-05-28 20:43 file1
-rw-r--r-- 1 owner group 0 2009-05-28 20:43 file2
-rw-r--r-- 1 owner group 0 2009-05-28 20:43 file3This listing output provides the file permissions, the user ID of the file owner, the group ID of the file owner, the file size, the date stamp, the time stamp, and finally, the file name.
Hidden Files
In Windows, files are hidden by setting a flag in the file properties. Linux uses a simpler method that has been used in Unix for years. Any file that starts with a "." is hidden by default. To view files in a directory, including the hidden files, use the -a switch with ls. Here's an example.
. .. file1 file2 file3 .hidden1This directory contains a hidden file called .hidden1. You'll also notice that there is a listing for "." and "..". The single dot is a shortcut that stands for the current directory. The double dot is a shortcut that stands for the parent directory.
A fundamental way that terminal commands work is that the options can be strung together to create the desired effect. To create a long listing of all files, you would enter
drwxr-xr-x 2 owner group 4096 2009-05-28 20:44 .
drwxr-xr-x 165 owner group 16384 2009-05-28 20:56 ..
-rw-r--r-- 1 owner group 0 2009-05-28 20:43 file1
-rw-r--r-- 1 owner group 0 2009-05-28 20:43 file2
-rw-r--r-- 1 owner group 0 2009-05-28 20:43 file3
-rw-r--r-- 1 owner group 0 2009-05-28 20:44 .hidden1The options can also be expressed in a number of ways. The following four ways will all yield the same output:
ls -al
ls -a -l
ls -l -a
To find out more about ls, just look at the manual page.

