Linux Command Line Interface: The Basics — Part 3

Austin Songer
Code The World
Published in
2 min readJan 15, 2017

3.0 Listing directory contents

Let’s list the ~/workspace directory contents

So we now know that we are currently on the /home/root/workspace. The pwd command tells us that.

How do we list what’s inside it?

  1. Click on the terminal window
  2. Type ls into the prompt
  3. Press the return key

Command: ls

Definition:
The ls or list directory contents command returns a horizontal list of the current directory and its contents.

Did the ls match the file tree contents?

Considering that we are currently at the ~/workspace (remember this is equivalent to /home/root/workspace), then the ls command should have listed what’s inside it.

3. 1. Hidden files

The ls command ommited directories and files with a dot

Look at the file tree. There are some files and directories that start with a dot that are not being printed by the ls command, why is that?

Hidden files and hidden directories

Dotfiles as they are usually known, are commonly used for storing user preferences or user configuration.

The intention of files or folders that start with a dot character is simply to not “clutter” the display of the contents of a directory listing with files the user did not directly create or wants to remain hidden from casual inspection.

Wondering if hidden files and folders can be listed?

Yes, they can be listed:

  1. Click on the terminal window
  2. Type: ls -a
  3. Press the return key

In addition to the ls command, we are typing 2 characters more: -a, this set of characters are called: command options.

3. 2. Command options

What does the -a character do

Executing the ls command outputs only the visible files on our current directory, however, as the file tree displays, there are some hidden directories and hidden files inside it.

Introducing: command options

After executing the ls -a command, we’ve got a larger output:

root ~/workspace $ ls -a
. .. dir1 empty-file.txt .git .gitignore .guides

Can you recognize the hidden vs. the normal files and folders?

Command options

Bash commands accept options after the command name. These options complement the command output by adding or structuring information regarding the text, file or directory over which the command is acting upon.

Command options are written after the command name and begin with a - symbol followed by the option character.

3. 3. The ls -a option in depth

Why are there dots without a name after them?

Take a closer look at the ls -a output listing our current directory contents.
Can you guess which are files and which are directories?:

root ~/workspace $ ls -a.                    refers to the current directory..                   refers to the parent directorydirl                 directoryempty-file.txt       file with .txt extension.git                 hidden directory.guides              hidden directory

As you can see, bash sorts files and directories alphabetically starting with the dots.

Single and double dots

Dots in bash are useful utilities that help on navigating the file system using the CLI.

In an ls listing

  • . refers to the current directory
  • .. refers to the parent directory, the directory immediately above the current directory.

--

--

Austin Songer
Code The World

Trusted Veteran | Compassionate. Aspiring. Resourceful.