Skip to main content

Listing Files and Flags

Welcome to the "Listing Files and Flags" page, your comprehensive guide to effectively navigate and explore file listings using various flags. This page covers the fundamental skill of listing files, allowing you to view the contents of directories and obtain vital information about files. Learn about the power of flags, which provide additional functionality and customization options when listing files. Gain insights into commonly used flags and how they can enhance your file listing experience. By mastering the art of listing files and understanding the various flags at your disposal, you'll be equipped with the tools to efficiently navigate and manage your files in the command line interface.

Objectivesโ€‹

By the end of this chapter, you should be able to:

  1. Understand what the ls command does
  2. Define flags and describe how the syntax works
  3. List files using flags

Listing Filesโ€‹

As you saw in the previous chapter, one of the most important commands you are going to be using is ls, which lists the contents of a directory. If you type ls in a directory you will see all sorts of content. For example, typing ls in your home directory will show you all of the files and folders inside of that directory. Typically your home directory contains folders such as Desktop, Documents, Downloads, Music, Pictures, etc.

Sometimes the default ls command does not give us all the information we want. In such cases, weโ€™ll need to add some flags to get more details.

Flagsโ€‹

In the previous chapter, we saw how flags could be used to modify the behavior of cp and rm. Flags can change and even enhance commands and are added using a - after the command. Flags are usually represented by single uppercase and lowercase letters. With the ls command, we can pass in the -a flag to list โ€œallโ€ files (including hidden files and folders). If we want the ls command to give us more information about each file, we can pass in the -l flag. To combine flags we can just use one - and pass in each flag. So the command to use ls and show all files and more detailed information about each one would be ls -la.

Using flags for ls will be essential when working with permissions as well as when you start working with git. We will also see many other terminal commands which accept flags later in this course.

When youโ€™re ready, move on to Terminal Basics Exercises