Linux for Starters

Linux for Starters: Your Guide to Linux – Files and Permissions – Part 10

This is a series that 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.

Linux for Starters - aliases

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

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.

Linux for Starters - ls

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.

Linux for Starters - ls

In the next image, la is an alias for ls -A. This also shows hidden files (these are files which begin with a .)

Linux for Starters - ls

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.

Linux for Starters - ls

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.

Linux for Starters - ls

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.

Page 2 – What does the long listing mean?

Pages in this article:
Page 1 – ls – list the contents of a directory
Page 2 – What does the long listing mean?
Page 3 – Appendix: Installing Hyper


All articles in this series:

Linux For Starters
Part 1What is Linux? Why use Linux? What do I need?
Part 2Choose a Linux distribution meeting your specific needs and requirements.
Part 3Make a bootable Ubuntu USB stick in Windows.
Part 4We show you how to install Ubuntu 21.04 on your hard disk.
Part 5Things to do after installing Ubuntu.
Part 6Navigating your way around the Desktop.
Part 7Updating the system, install new software.
Part 8Recommended open source replacements for proprietary Windows desktop software.
Part 9Get started with the power and flexibility of the terminal.
Part 10We cover the basics of files and permissions.
Part 11Getting help from your system.
Part 12Learn all about the file system.
Share this article

Share your Thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.