The Wayback Machine - https://web.archive.org/web/20241003182236/https://www.geeksforgeeks.org/dir-command-in-linux-with-examples/
Open In App

dir command in Linux with examples

Last Updated : 15 May, 2019
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

dir command in Linux is used to list the contents of a directory.

How is dir command different from ls?

dir command differs from 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 terminal, it does not produce colored output as ls does.

SYNTAX:

 dir [OPTION] [FILE] 

Useful options for dir command

1. -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.
SYNTAX:

 dir -a 

EXAMPLE:

2. -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.
SYNTAX:

 dir -A 

EXAMPLE:

3. -l –author option: Displays author of all the files. -l is required to display the contents in the form of a list.
SYNTAX:

 dir -l --author 

EXAMPLE:

4. -B or –ignore-backups option: Ignores listing of backed up files. These files end with a `~`.
SYNTAX:

 dir -B 

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

 dir --color 

EXAMPLE:

6. -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.

SYNTAX:

 dir -F 

EXAMPLE:

7. –file-type option: It is same as -F option, except that it does not append `*` to the executables.
SYNTAX:

 dir --file-type 

EXAMPLE:

8. –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.
SYNTAX:

 dir --format=WORD 

EXAMPLE 1:

EXAMPLE 2:

9. –hide=PATTERN or –ignore=PATTERN option: It ignores files described by shell PATTERN while listing the contents of a directory.
SYNTAX:

 dir --hide=PATTERN 

EXAMPLE:

10. -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.
SYNTAX:

 dir -n 

11. -r, –reverse option: List files in reverse order while sorting.
SYNTAX:

 dir -r 

EXAMPLE:

12.-R, –recursive option: List subdirectories recursively.
SYNTAX:

 dir -R 

EXAMPLE:

13.–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.
SYNTAX:

 dir --sort=PARAMETER 

EXAMPLE 1:

EXAMPLE 2:

14. –help option: Display the help options and exit.
SYNTAX:

 dir --help 

EXAMPLE:

15. –version option: Outputs version information and exit.
SYNTAX:

 dir --version 


Previous Article
Next Article

Similar Reads

Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
Konan - Advanced Web Application Dir Scanner
Directories on the target domain can contain some sensitive information about the Web-Application which should not be revealed. We can discover this hidden directory by automating our task. Konan is an automated tool for fuzzing the hidden directories from the target domain. Konan tool is an advanced Directory Scanner as it provided various feature
3 min read
atrm command in Linux with examples
atrm command is used to remove the specified jobs. To remove a job, its job number is passed in the command. A user can only delete jobs that belong to him. Only superuser can delete any job even if that belongs to another user. Syntax: atrm [-V] job [job...] Options: -V : Used to print the version number atrm -V job : Job number of the job which i
1 min read
expand Command in LINUX with examples
Whenever you work with files in LINUX there can be a situation when you are stuck with a file containing many tabs and whatever you need to do with a file requires that file with no tabs but with spaces. In this situation, the task looks quite simple if you are dealing with a small file but what if the file you are dealing with is very big or you n
3 min read
rcp Command in Linux with examples
There comes a time while using LINUX when there is a need to copy some information stored in a file to another computer. This can be done simply using rcp command line utility . Obviously there exists some other methods to complete the above mentioned task which are more secure (like scp or rsync) but this command lets you do this in the simple way
4 min read
fmt command in Linux with examples
fmt command in LINUX actually works as a formatter for simplifying and optimizing text files. Formatting of text files can also be done manually, but it can be really time-consuming when it comes to large text files, this is where fmt comes to rescue. fmt re-formats each paragraph in the file specified, writing to standard output. Here's the syntax
4 min read
unexpand command in Linux with Examples
To convert the leading spaces and tabs into tabs, there exists a command line utility called unexpand command. The unexpand command by default convert each spaces into tabs writing the produced output to the standard output. Here's the syntax of unexpand command : Syntax : $unexpand [OPTION]... [FILE]... where, OPTION refers to the options compatib
2 min read
anacron command in linux with examples
anacron command is used to execute commands periodically with a frequency specified in days. Its main advantage over cron is that it can be used on a machine which is not running continuously. In cron if a machine is not running on time of a scheduled job then it will skip it, but anacron is a bit different as it first checks for timestamp of the j
3 min read
expect command in Linux with Examples
expect command or scripting language works with scripts that expect user inputs. It automates the task by providing inputs. // We can install expect command using following if not installed // On Ubuntu $sudo apt install expect // On Redhat based systems $ yum install expect First we write a script that will be needing inputs from users and then we
2 min read
function command in Linux with examples
The function is a command in Linux that is used to create functions or methods. It is used to perform a specific task or a set of instructions. It allows users to create shortcuts for lengthy tasks making the command-line experience more efficient and convenient. The function can be created in the user's current shell session or saved in the shell
2 min read
Clear Command in Linux with Examples
clear is a standard Unix computer operating system command that is used to clear the terminal screen. This command first looks for a terminal type in the environment and after that, it figures out the terminfo database for how to clear the screen. And this command will ignore any command-line parameters that may be present. Also, the clear command
2 min read
Continue Command in Linux with examples
continue is a command which is used to skip the current iteration in for, while, and until loop. It is used in scripting languages and shell scripts to control the flow of executions. It takes one more parameter [N], if N is mentioned then it continues from the nth enclosing loop. The syntax for the `continue` command in Linuxcontinue or continue [
2 min read
hostid command in Linux with examples
hostid is a command in Linux that is used to display the Host's ID in hexadecimal format. It provides a quick and straightforward way to retrieve the host ID, allowing administrators to associate it with software licenses or perform system-specific operations. Syntax of `hostid` command in Linuxhostid [OPTION] Options provided by hostedhostid --hel
1 min read
Dirname Command in Linux with Examples
dirname is a command in Linux that is used to remove the trailing forward slashes "/" from the NAME and prints the remaining portion. If the argument NAME does not contain the forward slash "/" then it simply prints dot ".". In other words, we can say that the `dirname` command is a useful tool for extracting the directory portion from a given path
2 min read
factor command in Linux with examples
The factor command in Linux is used to print the prime factors of the given numbers, either given from command line or read from standard input. The numbers given through standard input may be delimited by tabs, spaces or newlines. Syntax: factor [NUMBER] Factor 100 (non-prime number): We get the prime factors 2 and 5 that make up 100. Factor 13 (p
1 min read
chpasswd command in Linux with examples
chpasswd command is used to change password although passwd command can also do same. But it changes the password of one user at a time so for multiple users chpasswd is used. Below figure shows the use of passwd command. Using passwd we are changing the password of the guest user. Here first you have to enter the password of the currently signed u
2 min read
eval command in Linux with Examples
eval is a built-in Linux command which is used to execute arguments as a shell command. It combines arguments into a single string and uses it as an input to the shell and execute the commands. Syntax eval [arg ...] Example: In the below figure, you can see that cd Desktop command is stored in a variable "CD" as a shell command. Now you can use thi
1 min read
lsmod command in Linux with Examples
lsmod command is used to display the status of modules in the Linux kernel. It results in a list of loaded modules. lsmod is a trivial program which nicely formats the contents of the /proc/modules, showing what kernel modules are currently loaded. Syntax: lsmod Example: Run lsmod at the command line to list all active kernel modules. lsmod Output:
1 min read
emacs command in Linux with examples
Introduction to Emacs Editor in Linux/Unix Systems: The Emacs is referred to a family of editors, which means it has many versions or flavors or iterations. The most commonly used version of Emacs editor is GNU Emacs and was created by Richard Stallman. The main difference between text editors like vi, vim, nano, and the Emacs is that is faster, po
5 min read
builtin command in Linux with examples
builtin command is used to run a shell builtin, passing it arguments(args), and also to get the exit status. The main use of this command is to define a shell function having the same name as the shell builtin by keeping the functionality of the builtin within the function. Syntax: builtin [shell-builtin [arg ..]] Example: Here, we are creating a f
1 min read
dc command in Linux with examples
dc command in Linux is used to evaluate arithmetic expressions. It evaluates expressions in the form of a postfix expression. Entering a number pushes it into the stack and entering an operator evaluates an expression and pushes the result back into the stack. It can evaluate +, -, /, *, %, ^. Different commands can be used to manipulate stack. Syn
2 min read
host command in Linux with examples
host command in Linux system is used for DNS (Domain Name System) lookup operations. In simple words, this command is used to find the IP address of a particular domain name or if you want to find out the domain name of a particular IP address the host command becomes handy. You can also find more specific details of a domain by specifying the corr
2 min read
yes command in Linux with Examples
yes, the command in Linux is used to print a continuous output stream of a given STRING. If STRING is not mentioned then it prints 'y'; Syntax: of `yes` command in Linuxyes [STRING] Note: To stop printing please press Ctrl + C. Use of `yes` commandlet us say that we want to delete all the `.txt` files present in the current directory. Instead of wr
2 min read
until command in Linux with Examples
until command in Linux used to execute a set of commands as long as the final command in the 'until' Commands has an exit status which is not zero. It is mostly used where the user needs to execute a set of commands until a condition is true. Syntax: until COMMANDS; do COMMANDS; done Here, if the COMMANDS get evaluated to false then the statements
1 min read
bzdiff command in linux with examples
bzdiff command in Linux is used to compare the bzip2 compressed files. Bzcmp and bzdiff are used to invoke the cmp or the diff program on bzip2 compressed files. All options specified are passed directly to cmp or diff. If only one file is specified, then the files compared are file1 and an uncompressed file1.bz2. If two files are specified, then t
1 min read
bzcmp command in Linux with examples
The bzcmp utility is used to invoke the cmp utility on bzip2 compressed files. All options specified are passed directly to cmp. As internally bzcmp calls cmp, We can pass the cmp command options to bzcmp. If only one file is specified, then the files compared are file1 and an uncompressed file1.bz2. If two files are specified, then they are uncomp
2 min read
fold command in Linux with examples
The fold command in Linux wraps each line in an input file to fit a specified width and prints it to the standard output. By default, it wraps lines at a maximum width of 80 columns, which is configurable. To fold input using the fold command pass a file or standard input to the command. Syntax of `fold` command in Linux fold [OPTION] [FILE] We can
3 min read
acpi_available command in Linux with examples
acpi_available is a command in Linux which test whether ACPI (Advanced Configuration and Power Interface) subsystem is available or not. It has three return statuses: 0 : It means ACPI subsystem is available.1 : It means ACPI subsystem is not available.2 : It means some usage error has occurred. Syntax: $ acpi_available Example 1: Here, echo $? is
1 min read
if command in linux with examples
if is a command in Linux which is used to execute commands based on conditions. The 'if COMMANDS' list is executed. If its status is zero, then the 'then COMMANDS' list is executed. Otherwise, each 'elif COMMANDS' list is executed in turn, and if its exit status is zero, the corresponding 'then COMMANDS' list is executed and the if command complete
1 min read