FactorPad
Faster Learning Tutorials

Linux ls command summary with examples

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.
Paul Alan Davis, CFA, October 5, 2016
Updated: July 26, 2018
In this tutorial, 7 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Next

~/ home  / tech  / linux essentials  / ls command


The Linux ls command

Beginner

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

Video Tutorial

Linux ls command summary with examples (3:49)

Videos can also be accessed from the YouTube Playlist.

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.

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 and check out our social media below. Who knows? We may beg to hire you some day.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the pwd command, hit Back.
  • To explore another popular Linux command #8 cd, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / ls command



 
 
Keywords:
linux ls command
ls linux
ls unix
linux list files
linux list directories
linux navigation
ls sort by date
ls options
list hidden files
list dot files
ls directories
ls command
ls tutorial
ls options