Database Reference
In-Depth Information
$
alias
l
=
'ls -1 --group-directories-first'
$
alias
moer
=
more
Now, if you type the following on the command line, the shell will replace each
alias it finds with its value:
$
cd
~
$
l
book
Aliases are simpler than shell functions as they don't allow parameters. The func‐
tion
fac
could not have been defined using an alias because of the parameter.
Still, aliases allow you to save lots of keystrokes. Like shell functions, aliases are
often defined in
.bashrc
or
.bash_aliases
configuration files, which are located in
your home directory. To see all aliases currently defined, you simply run
alias
without arguments. Try it, what do you see?
In this topic, when it comes to creating new command-line tools, we'll focus mostly
on the last three types: interpreted scripts, shell functions, and aliases. This is because
these can easily be changed. The purpose of a command-line tool is to make your life
on the command line easier, and to make you a more productive and more efficient
data scientist. You can find out the type of a command-line tool with
type
(which is
itself a shell builtin):
$
type
-a
pwd
pwd is a shell builtin
pwd is /bin/pwd
$
type
-a
cd
cd is a shell builtin
$
type
-a fac
fac is a function
fac ()
{
( echo 1;
seq $1 ) | paste -s -d\* | bc
}
$
type
-a l
l is aliased to `ls -1 --group-directories-first'
As you can see,
type
returns two command-line tools for
pwd
. In that case, the first
reported command-line tool is used when you type
pwd
. In the next section, we'll look
at how to combine command-line tools.
Combining Command-Line Tools
Because most command-line tools adhere to the Unix philosophy, they are designed
to do only one thing, and do it really well. For example, the command-line tool
grep
(Meyering, 2012) can filter lines,
wc
(Rubin & MacKenzie, 2012) can count lines, and
sort
(Haertel & Eggert, 2012) can sort lines. The power of the command line comes