Mastering Linux Commands: Listing files and folders in Linux File System

Welcome to our guide on how to use the ‘ls’ command in Linux to see your files and folders. This command is very helpful and is used in the Linux command line interface (also known as CLI or Terminal), which is like a text-only way of controlling your computer.

What is the ‘ls’ Command?

The ‘ls’ command lets you see all the files and folders where you are currently looking in your Linux system. When you type ‘ls’ and press enter, you will see a list, usually in the order the items were added or created.

If you need help or want to see what options you have with ‘ls’, you can type ‘ls --help’ in your terminal, and it will show you more details.

Getting Files from GitHub to Practice

To practice Linux commands, you can download example files and folders from a place called GitHub. First, ensure you have ‘git’ installed on your computer. Then, you can use a command to bring those examples onto your computer. It looks like this: git clone https://github.com/dgadiraju/data.git.

Setting Up Jupyter Lab for Learning

Jupyter Lab is a tool that lets you write and test out Linux commands easily and interactively. It’s a great environment, especially for learning and trying out new things.

Understanding File and Folder Properties with ‘ls’

When you add ‘-ltr’ to the ‘ls’ command (like this: ls -ltr), it shows you more details about each file and folder, such as when they were made or changed last. This command also sorts them in a specific order, making it easier to find what you’re looking for.

Sorting Files in Different Ways

You can sort files and folders using different criteria, like their size or when they were last updated. For example, ls -ltr sorts them by time and ls -S sorts them by size.

Discovering Hidden Files and Folders

In Linux, some files or folders are hidden and not shown by default. To see them, you use ‘ls’ with the ‘-a’ option, like this: ls -a. This command reveals every item, even the hidden ones.

Recursively Listing Contents

If you want to see everything inside a folder and its subfolders, you use ‘ls’ with ‘-R’. This command digs down into each folder, showing you everything inside.

Using Control Arguments and Understanding File Sizes

Control arguments are extra options you can add to the ‘ls’ command to change what it shows you. For example, adding ‘-h’ makes the file sizes easier to read (like showing ‘1K’ instead of ‘1024 bytes’).

Creating Shortcuts with Aliases

You can make shortcuts for commands you use a lot. For instance, you might see ‘ll’ used as a shortcut for a more detailed listing command. You can create these shortcuts using the ‘alias’ command.

We hope this guide helps you get more comfortable with the Linux ‘ls’ command and encourages you to explore more about what you can do in Linux!

Hands-on Tasks

Here are a few hands-on tasks that you can perform to practice using the ‘ls’ command and related concepts in Linux. These tasks will help reinforce the learning and provide practical experience:

Task 1: Basic Listing with ‘ls’

  1. Open your Linux terminal.
  2. Use the ls command to list all the files and folders in your current directory.
  3. Observe the output. Try to differentiate between files and folders based on the output.

Task 2: Using ‘ls’ with Options*

  1. In your terminal, list the contents of the current directory in long format using ls -l.
  2. Use ls -a to list all contents, including hidden files and directories. Compare the output with the previous command.
  3. Execute ls -lh to view the file sizes in a more readable format. Notice how the sizes are displayed differently compared to ls -l.

Task 3: Sorting Files and Directories

  1. Use ls -lt to list files and directories sorted by modification time. Identify which files or directories were modified most recently.
  2. Try ls -lS to sort the contents by file size. Determine which is the largest file.

Task 4: Working with Hidden Files

  1. Create a hidden file in your current directory: touch .myhiddenfile.
  2. Verify that ls does not show the hidden file, but ls -a does.

Task 5: Exploring Directories Recursively

  1. Create a nested directory structure: mkdir -p mydir/subdir/subsubdir.
  2. Use ls -R to recursively list all directories and subdirectories starting from ‘mydir’.

Task 6: Alias Creation and Usage

  1. Create an alias for a frequently used ls command, such as alias ll='ls -l'.
  2. Use your newly created alias ll and observe the output.
  3. Add this alias to your .bashrc or .zshrc file to make it permanent.

Task 7: Downloading and Exploring External Data

  1. Clone a sample data repository: git clone https://github.com/dgadiraju/data.git.
  2. Navigate into the cloned ‘data’ directory: cd data.
  3. Experiment with various ls commands to explore the files and directories within the ‘data’ folder.

By completing these tasks, readers like you will gain hands-on experience with the ls command and its various options, enhancing your proficiency in navigating and understanding the Linux filesystem.

Remember, practice is key to mastering Linux commands. Don’t hesitate to try out these commands and explore their options to deepen your understanding.


Thank you for exploring the Linux category on ITVersity! If you wish to engage further, such as participating in discussions, seeking support, or sharing your insights, please sign up if you haven’t already. Joining our community allows you to interact with fellow Linux enthusiasts and experts. Your contribution and participation will enrich our collective learning experience. Sign up today and be part of our vibrant community to discuss, learn, and grow together in the realm of Linux.