Listing files and folders in Linux File System

Vamsi Penmetsa
DevOps Engineering on Cloud
5 min readJul 19, 2022
ls command in Linux to list the files

As part of this article, you will see how to list files and folders in Linux File System using the ls command.

👨🏽‍💻🧑🏻‍💻For more ARTICLES, FOLLOW📍DevOps Engineering on Cloud

Overview of ls command to list files and folders in Linux

The ls command is one of the many Linux commands allowing users to list files or directories from the CLI.

Just like you navigate in your File Explorer or Finder with a GUI, the ls command allows you to list all files or directories in the current directory by default, and further interact with them via the command line.

When you type ls you can see the files or folders present in the present working directory in ascending order as shown in the below picture👇🏻

You can get help from the terminal using the ls --help command. You can check the Usage in the below picture👇🏻

🚨👉🏼 You can also check the complete udemy course (Linux Shell Commands for Absolute Beginners using Ubuntu 20x)🔗Referral link

Overview of ls command to list files and folders in Linux detailed video

Setup Files and Folders from GitHub Account to learn Shell Commands

You need more folders to practice the Linux commands so we have the repo with sample data. You can download it to your computer by following the steps below👇🏻

Make sure git is installed on your computer and then you can use the following command to clone the repo to your current working directory.👇🏻

Once the data folder is cloned to your computer, Then you can enter into the data folder using the cd command. This is what the cloned folder looks like👇🏻

Files in the data folder cloned from the repository
Setup Files and Folders from GitHub Account to learn Shell Commands detailed video

How to Setup Jupyter Lab? (to go through help on Linux commands)

If you want to learn how to set up the jupyter lab to practice the Linux command on the virtual environment in the most interactive way then you need to check out the following timestamp from the video👇🏻

“How to Setup Jupyter Lab?” detailed video

Getting the properties of files and folders using ls command in Linux

When you type ls -ltr you can see the output as follows. By seeing the color code you can differentiate between files and folders. The blue color is a folder and the white color is a file. 👇🏻

the output of the ls -ltr command in the Linux terminal

But, the other way to differentiate them is by looking at the first characters of the output. If it has d(directory) at starting then it's a folder.

Now let's know what ls -ltr means. If you type ls --help then you can read the usage of -ltr 👇🏻

-l                         use a long listing format
-t sort by time, newest first; see --time
-r, --reverse reverse order while sorting
Getting the properties of files and folders using ls command in Linux detailed video

Sorting ls output while listing files in Linux

You can sort the output by using the above ls -ltr command.

ls -ltr command

📌 A clear explanation of what happened in the above code snippet will be in this video timestamp👇🏻

List files and folders in Linux sorted by time

You can also use ls -l -t -r the results will be the same as ls -ltr

listing files and folders in Linux

List files and folders in Linux sorted by size

You can sort the files and folders based on the size -Scontrol argument. You can use the following set of control arguments to sort the files ls -S you are using the uppercase alphabet S.

-S                         sort by file size, largest first

Without using ls -S

sorting files by size

With using ls -S You can see the output got sorted in descending order by file size in the 4th column

Sorting files by using the size control argument
List files and folders in Linux sorted by size detailed video

Overview of Hidden Folders and Files

To get the list of hidden files, use the following control argument along with ls command

-a, --all                  do not ignore entries starting with .

So, the final commands will look like ls -a

To deep dive into the command, you can visit this timestamp video 👇🏻

Listing the files and folders recursively in Linux

To recursively visit the files and folders inside the particular directory you can use the following control argument. It's uppercase R.

-R, --recursive            list subdirectories recursively

And the command is ls -R

Recursively check the folders on Linux by using the ls -R command

You can tweak the above command by introducing -lto it ls -lR the output looks like the following👇🏻

Using the ls -lR command

Exploring Control Arguments while listing files in Linux

Control arguments are very powerful and helpful for being productive in day-to-day tasks in Linux. You can get complete help about how to use these control arguments from the terminal itself. Here is the summary of how to explore and use the control arguments in the Linux terminal without googling and wasting time.

📌 Timestamp of the video to explore control arguments in Linux terminal👇🏻

Exploring Control Arguments while listing files in the Linux terminal

Overview of representation of file sizes

In Linux, you can use human-readable -h control argument along with ls command like this👉🏼ls -lh

It will help to understand the file sizes by converting the bytes to a human-readable format.

-h, --human-readable       with -l and -s, print sizes like 1K 234M 

For example, you can check the below images.👇🏻

📌 Without using -h a control argument. Check out 4th column below

Without using -h a control argument in Linux

📌 With using -h a control argument in ls ls -lh. Check out 4th column below

With using -h a control argument in ls ls -lh

The file sizes are in Megabytes and kilobytes like 1K 234M.

Overview of representation of file sizes detailed video

Overview of alias command and ll to list files and folders

In Linux, you can define an alias for the most frequently used commands. You can define it by using the following syntax👇🏻

alias ll='ls -alF'

📌If you want to learn about alias clearly with a video explanation check out the below video timestamp👇🏻

Overview of alias command and ll to list files and folders

🙏🏼Thank you, for reading the article. If you find it valuable please follow our publication DevOps Engineering on Cloud

🚨👉🏼 You can also check the complete udemy course (Linux Shell Commands for Absolute Beginners using Ubuntu 20x)🔗Referral link

--

--

Vamsi Penmetsa
DevOps Engineering on Cloud

Lead SRE | AGI Enthusiast 🥑 | ♾ DevOps Community Builder | From Tester in INDIA→ Lead SRE in EU 🇪🇺