Skip to main content

Module 1: File & Directory Management

Lesson 15: dir Command

In this lesson, you'll learn how to use the dir command to list the contents of a directory in Linux.

The dir command lists the contents of a directory. It is not a commonly used command in Linux, but it works similarly to the ls command which most Linux users prefer to use.

dir Command Syntax

$ dir [OPTION] [FILE]

dir Command Options

Option Description
-1 List one file per line
-a List all files including hidden files
-l Format output as a long list with detailed information
-d List directory entries instead of directory contents
-i Show the index number (inode) of each file
-s Show the size of each file
-S Sort files by size
-h Display file sizes in human-readable format
-t Sort files by modification time
-g List files without the file owner
-G List files without the group owner
-n Show numeric user and group IDs
-m List files separated by commas
-R List directories and subdirectories recursively
--author Show the author of each file
--group-directories-first List directories before files
--help Display help information
--version Display version information

1. List Files and Directories

The most common usage of the dir command is to display the contents of a directory in ascending alphabetical order.

If you run the dir command without any options or location of the directory, it will display all files and directories in your current working directory.

$ dir
Desktop  Documents  Downloads  Music  Pictures  Public  Videos

2. List Files in a Particular Path

If you want to list all the files and directories of a particular path, then append the path of your directory as shown.

Here, we will list files and directories under the /etc directory.

$ dir /etc
adduser.conf  bash.bashrc  cron.d  default  environment  fstab  hostname
hosts  hosts.allow  hosts.deny  issue  mtab  networks  passwd  profile

3. List One File Per Line

To list one file per line, use the -1 option as follows.

$ dir -1 /etc
adduser.conf
bash.bashrc
cron.d
default
environment
fstab
hostname

4. List Hidden Files and Directories

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’