---
title: "Learning the dir Command in Linux Through Examples"
description: "Learn all the ways that the dir command in Linux can help you navigate and manage files and folders in this ATA Learning tutorial!"
canonical: "https://adamtheautomator.com/dir-command-in-linux/"
---

# Learning the dir Command in Linux Through Examples

> Learn all the ways that the dir command in Linux can help you navigate and manage files and folders in this ATA Learning tutorial!

Source: https://adamtheautomator.com/dir-command-in-linux/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Learning the dir Command in Linux Through Examples](https://adamtheautomator.com/wp-content/uploads/2022/10/Learning-the-dir-Command-in-Linux-Through-Examples.jpg)

# Learning the dir Command in Linux Through Examples

[![](https://secure.gravatar.com/avatar/1bc5e1d52466fc3739f550c8d78be310684747bf1466a98d698320627ea243e2?s=192&d=mm&r=g)Michael Nguyen Tu](https://adamtheautomator.com/author/michael-nguyen-tu/)21 October 20226 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Linux](/tag/linux/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Listing Files and Folders (Basic dir Command in Linux)](#listing-files-and-folders-basic-dir-command-in-linux)
*   [Listing Files and Directories in a Specific Path](#listing-files-and-directories-in-a-specific-path)
*   [Listing Hidden Files and Directories](#listinghidden-files-and-directories)
*   [Retrieving Detailed List of Files and Directories](#retrieving-detailed-list-of-files-and-directories)
*   [Showing File Type Information](#showing-file-type-information)
*   [Customizing Output Format](#customizing-output-format)
*   [Ignoring Files with a Specific Pattern](#ignoring-files-with-a-specific-pattern)
*   [Sorting the Output of the dir Command](#sorting-the-output-of-the-dir-command)
*   [Conclusion](#conclusion)

As a system administrator, you’d typically work most of the time in a command line environment, and one essential skill is navigating your file system. With the `dir` command in Linux, you’re one step closer to mastering that skill.

The `dir` command allows you to view the contents of a directory, a handy command to know in finding files and folders on your system. And in this tutorial, you’ll learn how to navigate your file system through a series of examples.

Ready? Stay tuned and never be astray in finding your files and folders!

## Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have a Linux system. This tutorial uses [Ubuntu 20.04](https://adamtheautomator.com/install-ubuntu/), but any modern Linux distribution will work.

Related:[How to Install Ubuntu 20.04 \[Step-by-Step\]](https://adamtheautomator.com/install-ubuntu/)

## Listing Files and Folders (Basic dir Command in Linux)

The most basic use of the `dir` command is to list the files and folders in the current directory, which is handy, especially if you’re working in a terminal.

The basic syntax for the `dir` command is as follows where:

*   `<path>` – is the path to the directory you want to list
*   `<option>` – is an optional parameter to control the behavior of the `dir` command (will be covered in more detail later).

```bash
dir <path> <option>
```

Suppose you want to see all files and folders under the current working directory. If so, you’ll only need the bare minimum.

Run the `dir` command below with no options and no path to list all files and folders in your working directory.

```bash
dir
```

The output below shows you the names of all files and folders in your current directory, in this case, your home (root) directory.

![Listing all files and folders in the working directory](https://adamtheautomator.com/wp-content/uploads/2022/10/image-292.png)

Listing all files and folders in the working directory

## Listing Files and Directories in a Specific Path

Perhaps you want to list all files and folders in a specific path rather than the ones in your current working directory. In that case, appending the `<path>` option comes in handy.

You can use an absolute path or a relative path with the `dir` command:

*   An absolute path is a full path from the root of your file system.
*   A relative path is a path from your current working directory.

Run the below `dir` command to list files and directories under the `/etc` directory.

```bash
dir ~ /etc
```

![Listing files and directories under a specific path](https://adamtheautomator.com/wp-content/uploads/2022/10/image-293.png)

Listing files and directories under a specific path

## Listing Hidden Files and Directories

You may have noticed that when you run the `dir` command without any options, you’ll only see visible files listed in the output. But what about the hidden files?

In Linux, hidden files and directories start with a ‘.’ (dot) symbol. These files and directories are usually configuration files or folders.

Run the following `dir` command to list all files and directories, including the hidden ones (`-a`).

```bash
dir -a
```

The output below shows all files and directories in your current directory, including hidden ones such as **.bashrc,** a configuration file for the Bash shell.

You can also see two [symbolically linked (symlinks)](https://en.wikipedia.org/wiki/Symbolic_link) directories at the beginning of the list, which are called:

<table><tbody><tr><td><strong>Symlink</strong></td><td><strong>Description</strong></td></tr><tr><td>.</td><td>Link to your current directory</td></tr><tr><td>. .</td><td>Link to your current directory’s parent directory</td></tr></tbody></table>

![Listing hidden files and directories](https://adamtheautomator.com/wp-content/uploads/2022/10/image-294.png)

Listing hidden files and directories

> _Perhaps you prefer to exclude the symlinks from the list. If so, run the same dir command, but this time, append the -A option in uppercase. dir -A_

![Excluding the symlinks from the list](https://adamtheautomator.com/wp-content/uploads/2022/10/image-295.png)

Excluding the symlinks from the list

## Retrieving Detailed List of Files and Directories

The output from running the `dir` command is helpful but can be confusing and challenging to determine which is which, especially when there are many files and directories. As a solution, append the `-l` option in your `dir` command.

Run the below command to list all directories and files and their detailed information.

```bash
dir -l
```

As you can see below, each file and directory is listed on its own line. Notice each item’s format (_Desktop_, for example) below.

This behavior is advantageous when you want to take a quick look at the permissions on a file or directory.

<table><tbody><tr><td><strong>Permissions</strong></td><td><strong>Owner</strong></td><td><strong>Group Owner</strong></td><td><strong>Size</strong></td><td><strong>Last Modified Date and Time</strong></td></tr><tr><td>drwxr-xr-x</td><td>root</td><td>root</td><td>4096</td><td>Jul 16 16:45</td></tr></tbody></table>

Related:[A Windows Guy in a Linux World: Users and File Permission](https://adamtheautomator.com/linux-file-permissions/)

> _Some of these columns might not have any information. Why? Not all file types have permissions, owners, or groups. For example, symbolic links don’t have any of these attributes._

![Listing detailed files and directories](https://adamtheautomator.com/wp-content/uploads/2022/10/image-296.png)

Listing detailed files and directories

## Showing File Type Information

For more experienced Linux users, knowing what file type you’re dealing with can be helpful. If you’re unsure of the file type (i.e., a regular file or a directory), appending the `-F` option with the `dir` command will do the trick.

Run the following `dir` command to list all files and directories, including their file type.

```bash
dir -F
```

As you can see below, for each file and directory listed, there is a symbol at the end of the line that indicates their file type.

The most common symbols are as follows:

<table><tbody><tr><td><strong>Symbol</strong></td><td><strong>File Type Equivalent</strong></td></tr><tr><td>/</td><td>Directory</td></tr><tr><td>*</td><td>Executable File</td></tr><tr><td>@</td><td>Symbolic Link</td></tr><tr><td>=</td><td>Socket</td></tr><tr><td>|</td><td>FIFO (first in, first out) file</td></tr></tbody></table>

![Showing file type information](https://adamtheautomator.com/wp-content/uploads/2022/10/image-297.png)

Showing file type information

## Customizing Output Format

By default, the `dir` command’s output is formatted in columns. But if you want to see the output differently, the `--format` option can help.

1\. Run the below dir command to list the files and directories in a single column.

```bash
dir --format=single-column
```

As you can see below, the output shows the list of files and directories in one column, making a list more readable.

![Listing the files and directories in a single column](https://adamtheautomator.com/wp-content/uploads/2022/10/image-298.png)

Listing the files and directories in a single column

2\. Next, run the same dir command below to list all files and directories. But this time, change the –format option’s value to commas.

This command changes the output’s format to comma-separated values, which can be used for machine parsing.

```bash
dir --format=commas
```

As you can see below, all files and directories are listed and separated by commas.

![Listing files in comma-separated values](https://adamtheautomator.com/wp-content/uploads/2022/10/image-299.png)

Listing files in comma-separated values

3\. Now, run the following command to list all files and directories in –verbose to show more information.

```bash
dir --format=verbose
```

Below, you can see the –format=version option outputs the same as dir -l command.

![Using the --format=verbose option to show even more information](https://adamtheautomator.com/wp-content/uploads/2022/10/image-300.png)

Using the –format=verbose option to show even more information

## Ignoring Files with a Specific Pattern

The `dir` command is often used in Bash scripts, to ignoring certain file types might be helpful to speed up the script execution. For example, if you’re looking for all the regular files in a directory, you might want to ignore any symbolic links. Lucky for you, the `--ignore` option lets you do the magic.

Related:[Learn Multi-Threading Bash scripts with GNU Parallel](https://adamtheautomator.com/how-to-speed-up-bash-scripts-with-multithreading-and-gnu-parallel/)

Run the below `dir` command to list all files and directories in the current directory, except for any symbolic links (`@`).

```bash
dir --ignore=@ -F
```

As you can see below, only regular files and directories are listed, and any symbolic links that might be present in the directory are ignored.

![Ignoring symbolic links](https://adamtheautomator.com/wp-content/uploads/2022/10/image-301-1024x322.png)

Ignoring symbolic links

Now, run the following command to list all files and directories while ignoring any executable files (`*.exe`).

```bash
dir --ignore=*.exe -F
```

You can confirm in the output below that this command extensively narrows files and directory listings since you’re excluding executable files.

![Ignoring any executable files](https://adamtheautomator.com/wp-content/uploads/2022/10/image-302.png)

Ignoring any executable files

## Sorting the Output of the `dir` Command

Naturally, when you run the `dir` command, files and directories are listed in ascending order alphabetically. But perhaps you want to list the files and directories in a certain order, for example, in size order or by the last modified date.

In that case, you can use other options for the `dir` command to sort the list of files and directories in the output.

Run the below command to list all files and directories in the current directory by size, with the largest ones listed first.

```bash
dir -S -l
```

![Listing all of the files and directories by size,](https://adamtheautomator.com/wp-content/uploads/2022/10/image-303.png)

Listing all of the files and directories by size,

Finally, run the following `dir` command to list files and directories sorted by time. Note that the topmost file or directory is the one that was most recently modified.

```bash
dir -t -l
```

![Listing files and directories sorted by date and time](https://adamtheautomator.com/wp-content/uploads/2022/10/image-304.png)

Listing files and directories sorted by date and time

## Conclusion

The essential skill any Linux user needs is the ability to list the files and directories in their file system. And In this tutorial, you’ve looked at some of the more common options for the `dir` command in Linux to navigate your file system effectively.

At this point, you should be confident enough to work with your file system via your terminal as long as you have the `dir` command. Why not try writing a script that automatically finds files and directories to manage on your system?

Related:[Your One and Only Linux Shell Scripting Tutorial](https://adamtheautomator.com/linux-shell-scripting-tutorial/)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fdir-command-in-linux%2F&text=Learning%20the%20dir%20Command%20in%20Linux%20Through%20Examples)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fdir-command-in-linux%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fdir-command-in-linux%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Practical-Linux-Unix-Tee-Commands-for-the-Linux-Admin.jpg)

### [Master Unix tee Commands for Real-World Linux Admin Tasks](/unix-tee/)

Simplify Linux output management and streamline your workflow with the “Unix tee” command. This tutorial guides you through its practical applications.

![](https://adamtheautomator.com/wp-content/uploads/2024/03/openldap-4.jpg)

### [How to Install and Configure an OpenLDAP Ubuntu Server](/openldap/)

Unlock the power of OpenLDAP on Ubuntu for centralized user authentication, seamless access control management, and enhanced directory services!

![](https://adamtheautomator.com/wp-content/uploads/2024/03/pipe-command-in-linux-1.jpg)

### [Unleashing the Power of the Pipe Command in Linux](/pipe-command-in-linux/)

Unlock the prowess of the pipe command in Linux to streamline tasks, boost productivity, and simplify complex operations effortlessly!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
