FactorPad
Build a Better Process

Linux ls Command Summary with Examples

Linux ls allows you to list files in a directory.
  1. Purpose - Learn what ls is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with ls.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial on Linux ls, 7 to 10, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / ls-command.html


An ad-free and cookie-free website.


Examples of the Linux ls Command

Beginner

Learn to list files and directories at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux ls Command Summary with Examples (3:49)

Video Script

The Command and Why You Need It

Our seventh word, or command to memorize is ls from the category Navigation.

ls allows you to list files in a directory. In our last video we used pwd to find the directory name, now with ls we can look inside it.

Common Linux ls Options
-options description
-a List all files
-l List files with details

If it helps, think of commands as mini programs and most have this structure. First, type the command, second the -option(s) and third the argument(s).

The ls command has over 30 options and its argument can be a different directory than your current directory, or it can be a wildcard to show files or directories of a certain type.

Now, we will focus on two options, but I think you'll benefit from knowing other options, so please review the man ls page later.

First is ls -a, which lists all files. By default, files that start with a 'dot' . are for profile settings and are not listed without -a.

Second, -l lists details of each file (or directory).

So why is ls an important command? Well, Linux is an open language, and to get around and make it useful you need to explore and view files. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows 10.

Here we go, start with ls and no options and no arguments and there is the text file we created in video 5.

$ ls video5.txt

Next, type ls -a to include semi-hidden configuration files.

$ ls -a . .. .bash_history .bash_logout .bashrc .profile video5.txt

Third, let's use the ls -l option to see permissions, owners, file size, date modified and the file name.

$ ls -l total 4 -rw-r--r-- 1 paul paul 176 Oct 5 13:48 video5.txt

And last, put two options together, in either order, and inspect.

$ ls -al total 28 drwxr-xr-x 2 paul paul 4096 Oct 5 13:48 . drwxr-xr-x 5 root root 4096 Sep 27 22:24 .. -rw------- 1 paul paul 30 Sep 27 22:31 .bash_history -rw-r--r-- 1 paul paul 220 Sep 27 22:24 .bash_logout -rw-r--r-- 1 paul paul 3515 Sep 27 22:24 .bashrc -rw-r--r-- 1 paul paul 675 Sep 27 22:24 .profile -rw-r--r-- 1 paul paul 176 Oct 5 13:48 video5.txt

A Final Tip

Okay now you know how to use ls. And you know the syntax for commands, options and arguments.

One last tip about the ls command. Many users customize their ls command to save keystrokes, and we'll cover how to do this later.

Okay, thanks for visiting today. I hope this was a fun introduction to the ls command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

Subscribe at YouTube and follow @factorpad so we don't lose the connection. Who knows? We may beg to hire you some day.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / ls-command.html


Linux ls command
linux ls
ls command
ls linux
ls unix
ls sort by date
ls options
unix ls
ls command linux
ls order by date
ls linux command
linux command ls
ls directories
linux list files
show hidden files

A newly-updated free resource. Connect and refer a friend today.