Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App

dir command in Linux with examples

Last Updated : 10 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The dir command in Linux is used to list the contents of a directory, providing an overview of the files and folders within it.

How is the dir command different from ls?

dir command differs from the ls command in the format of listing contents that is in default listing options. By default, dir command lists the files and folders in columns, sorted vertically and special characters are represented by backslash escape sequences. But unlike ls, when the output is on the terminal, it does not produce colored output as ls does.

Syntax

 dir [OPTION] [FILE] 

where,

  • OPTION: Various flags can be used to modify the output, such as -a for showing hidden files or -l for a long listing format.
  • FILE: The directory or file to list. If not specified, the current directory is used.

Commonly Used Options with the dir Command

1. Display All Files Including Hidden Files (-a or --all option):

It displays all the hidden files(starting with `.`) along with two files denoted by `.` and `..` which signals for current and previous directory respectively.

 dir -a 

Example:

Display All Files Including Hidden Files

2. Show Almost All Files (-A or --almost-all option):

It is similar to -a option except that it does not display files that signals the current directory and previous directory.

 dir -A 

Example:

Show Almost All Files

3. Display Author Information (-l --author option):

Displays author of all the files. -l is required to display the contents in the form of a list.

 dir -l --author 

Example:

Display Author Information

4. Ignore Backup Files (-B or --ignore-backups option):

Ignores listing of backed up files. These files end with a `~`.

 dir -B 

5. Enable Colored Output (--color option):

It is used to colorize the output (can be followed by =[TIME]). In the absence of time specification which can be auto, never or always, it colorizes the output always (default behavior).

dir --color 

Example:

Enable Colored Output

6. Classify File Types (-F, --classify option):

Append indicator (one of */=>@|) to the file names which classifies them into their type. The meanings of symbols are as follows:

  • A slash (`/`) indicates a directory.
  • An asterisk (`*`) indicates an executable.
  • An at sign (`@`) indicates a symbolic link.
  • A percent sign (`%`) indicates a whiteout.
  • An equal sign (`=`) indicates a socket.
  • A vertical bar (`|`) indicates a FIFO.
dir -F 

Example:

7. Show File Types Without Executable Indicator (--file-type option):

It is same as -F option, except that it does not append `*` to the executables.

dir --file-type 

Example:

Show File Types Without Executable Indicator

8. Format Output (--format=WORD option):

It formats the listing of entries. The WORD can take the following values: across, commas, horizontal, long, single-column, verbose, vertical. The same can be achieved by passing -x, -m, -x, -l, -1, -l, -C options to dir command for each of the respective values.

dir --format=WORD 

Example 1:

Example 2:

9. Ignore Files Matching a Pattern (--hide=PATTERN or --ignore=PATTERN option):

It ignores files described by shell PATTERN while listing the contents of a directory.

dir --hide=PATTERN 

Example:

10. Display Numeric User and Group IDs (-n, --numeric-uid-gid option):

This option is similar to the long listing that is -l option except that it lists numeric user and group IDs.

 dir -n 

11. List Files in Reverse Order (-r, --reverse option):

Use this option to list the files in reverse order based on the sorting criteria.

 dir -r 

Example:

List Subdirectories Recursively

12. List Subdirectories Recursively (-R, --recursive option):

The -R option lists all subdirectories recursively, making it useful for exploring directory structures.

 dir -R 

Example:

List Subdirectories Recursively

13. Sort Files by a Specified Parameter (--sort=PARAMETER):

To list files in a sorted manner described by the PARAMETER. The PARAMETER can take the following values: none (-U), size (-S), time (-t), version (-v), extension (-X). Instead of passing --sort option, the flags indicated in the brackets can directly be passed as options to sort the listing.

 dir --sort=PARAMETER 

Example 1:

Example 2:

14. Display Help Information (--help option):

Use the --help option to display a list of all available options and exit.

dir --help 

Example:

Display Help Information

15. Show Version Information (--version option):

The --version option displays the version of the dir command.

dir --version 
Show Version Information

Conclusion

The dir command in Linux is a versatile and valuable tool for listing directory contents. It offers various options for displaying file information, sorting, and filtering results, making it a useful alternative to the ls command. By mastering the dir command, you can effectively navigate and manage your Linux filesystem.


A

Archana choudhary
Improve
Article Tags :
  • Linux-Unix
  • linux-command
  • Linux-directory-commands

Similar Reads

    cupsd command in Linux with examples
    cupsd is a type of scheduler for CUPS (Common Unit Printing System). It implements the printing system on the basis of the Internet Printing Protocol(Version 2.1). If no options is being specified on the command-line then the default configuration file /etc/cups/cupsd.conf will be automatically be u
    3 min read
    curl Command in Linux with Examples
    curl is a command-line utility for transferring data to or from a server, employing a range of internet protocols such as HTTP, HTTPS, FTP, SCP, and SFTP.Whether you want to download a file, test a REST API, or simply verify that a website is up and running, curl is your best friend. It is accessed
    5 min read
    cut command in Linux with examples
    The cut command in linux is a command for cutting out the sections from each line of files and writing the result to standard output. It can be used to cut parts of a line by byte position, character, and field. The cut command slices a line and extracts the text. It is necessary to specify an optio
    8 min read
    cvs command in Linux with Examples
    In today's digital era, where file modifications and version control are essential, the Concurrent Versions System (CVS) command in Linux emerges as a powerful tool. CVS allows users to store and track the history of files, enabling easy retrieval of previous versions and restoring corrupted files.
    6 min read
    How to Display and Set Date and Time in Linux | date Command
    Unlock the full potential of the date command in Linux—a versatile tool that does more than just show the current date and time. With this command, you can set your system’s clock, synchronize time across networks, and even calculate past or future dates for tasks like scheduling or logging. In this
    8 min read
    dc command in Linux with examples
    The dc command is a versatile calculator found in Linux systems, operating using reverse Polish notation (RPN). This command allows users to perform arithmetic calculations and manipulate a stack, making it ideal for complex mathematical tasks directly from the command line.SyntaxThe basic syntax fo
    3 min read
    'dd' Command in Linux: Explained
    The dd command in Linux is a powerful utility for low-level data copying and conversion, primarily used for disk cloning, creating disk images, partition backups, and writing ISO files to USB drives. Mastering the dd command is essential for Linux system administrators, as it enables precise control
    6 min read
    declare command in Linux with Examples
    The built-in is a powerful built-in feature of the Bash shell. It allows users to declare and set attributes for variables and functions, enabling better control over their behavior. By understanding how to use declare, you can manage variables and functions more effectively in your shell scripts. T
    2 min read
    depmod command in Linux with examples
    depmod(Dependency Modules) command is used to generate a list of dependency description of kernel modules and its associated map files. This analyzes the kernel modules in the directory /lib/modules/kernel-release and creates a "Makefile"-like dependency file named modules.dep based on the symbols p
    7 min read
    df Command in Linux with Examples
    There might come a situation while using Linux when you want to know the amount of space consumed by a particular file system on your LINUX system or how much space is available on a particular file system. LINUX being command friendly provides a command line utility for this i.e. 'df' command that
    9 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences