Defining new aliases

We can define our own aliases to get similar option-defining shortcuts. Suppose we've been typing ls -l a lot to get a full file listing of the current directory. Because we run it so often, we'd like a way to type it with fewer keystrokes. We can define an ll alias like this:

bash$ alias ll='ls -l'

The ll name is thereafter available as a command that will expand to run the full ls -l command instead:

bash$ type ll
ll is aliased to `ls -l'
bash$ ll
total 16
-rw-r--r-- 1 bashuser bashuser 3526 Jul 15 16:42 .bashrc
-rw-r--r-- 1 bashuser bashuser  675 Jul 15 16:42 .profile

We can add further options to our call to the ll alias, such as specifying a file on which the command should run, in this case .bashrc:

bash$ ll .bashrc
-rw-r--r-- 1 bashuser bashuser 3526 Jul 15 16:42 .bashrc

We can verify this by briefly turning on the -x option for the shell, which will print the expanded command before executing it, after a + prefix:

bash$ set -x
bash$ ll .bashrc
+ ls -l .bashrc
-rw-r--r-- 1 bashuser bashuser 3526 Jul 15 16:42 .bashrc
bash$ set +x