This series offers a gentle introduction to Linux for newcomers.
In the previous article in this series we presented an introduction to the Bash shell. We explained the 4 types of commands that are available in the shell: Builtins, Aliases, External commands, and Functions.
In this article we’ll take you through the basics of files and permissions. We’ll use the ls command. It’s an external command provided the GNU core utilities, a package that is present on your Ubuntu installation. The package provides the basic file, shell, and text manipulation utilities (96 separate commands).
Let’s see how to list the contents of a directory in different ways, and explain what the output means. Before doing so, let’s recap the aliases that Ubuntu 21.04 has defined. As the image shows, there are 4 aliases that use ls.
We are using hyper for our screenshots rather than the default Terminal app (gnome-terminal). If you want to install hyper, see the appendix.
ls is a command that lists the contents of a directory. By default it sorts entries alphabetically. In Linux everything is represented as a file.
Had Ubuntu not defined an alias for
ls, files would be output in the same color. But typing
ls actually invokes the command
ls --color=auto. With this option, directories are shown in blue, compressed files (such as zip files) are shown in red etc.
We next run
l which is an alias for
ls -CF. The -C option lists entries by columns, the -F option appends an indicator to entries.
In the next image,
la is an alias for
ls -A. This also shows hidden files (these are files which begin with a .)
In the next example, we issue the command
ll. That’s an alias for
ls -alF. This shows hidden files, files are shown in the long format, and appends an indicator to each entry.
Make your own ls alias
You may find that Ubuntu’s preconfigured aliases for
ls are not what you want. For example, we prefer different options for ls, as shown in the image below.
With this command, directories are grouped first before files. And file sizes are in human readable format.
Don’t type a long command each time. Let’s change the
ls alias by editing ~/.bashrc with nano, a simple text editor.
$ nano ~/.bashrc
Replace the line
alias ls='ls --color=auto' with
alias ls='ls -lAh --group-directories-first --color=auto'. Save the file with Ctrl + O and press Return.
Then either restart the terminal or enter the command
$ source ~/.bashrc
Now when we execute
ls we get the output shown in the last image.
The information that you see in the long format warrants further comment.
All articles in this series: