Page 48 - Raspberry Pi as a Foundation for Boosting Computer and Technology Literacy
P. 48
3 Fundamentals of the Linux system and terminal usage
Creating a command alias
Aliases in bash serve as convenient shortcuts that can replace long,
complex commands or commands with many flags and arguments.
They can save the user a lot of time typing, making their interaction
with the terminal more efficient.
Consider, for instance, the ls command with many useful flags,
such as showing the files’ sizes, listing them one per line, enabling col-
our in the output, and more, such as this one:
ls –human-readable –size -l -S –classify –col-
or=auto –group-directories-first
To create an alias for it, let us open the ‘.bashrc’ file in Nano:
nano .bashrc
Then, append the following alias at the end of the file (Figure 3.24):
alias ls=’ls --human-readable --size -1 -S
--classify --color=auto --group-directo-
ries-first’
Finally, save and exit the file, and run the following command for
the changes to take effect:
source .bashrc
Now, instead of running the aforementioned long ls command and
spelling out all its flags, one can simply run ‘ls’, and the long version of
the command will be executed.
Figure 3.24 Appending an alias to the .bashrc file
48