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.
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:
|Linux For Starters|
|Part 1||What is Linux? Why use Linux? What do I need?|
|Part 2||Choose a Linux distribution meeting your specific needs and requirements.|
|Part 3||Make a bootable Ubuntu USB stick in Windows.|
|Part 4||We show you how to install Ubuntu 21.04 on your hard disk.|
|Part 5||Things to do after installing Ubuntu.|
|Part 6||Navigating your way around the Desktop.|
|Part 7||Updating the system, install new software.|
|Part 8||Open source replacements for proprietary Windows desktop software.|
|Part 9||Get started with the power and flexibility of the terminal.|
|Part 10||We cover the basics of files and permissions.|
|Part 11||Getting help from your system.|
|Part 12||Learn all about the file system.|
|Part 13||Manipulating files from the shell.|
|Part 14||Maintain your system with these simple tips.|
|Part 15||Managing users on your system.|
|Part 16||Explore different desktops to GNOME 3.|
|Part 17||Gaming on Linux.|
|Part 18||Protect your privacy with this guide.|