Linux dirs command: displays a list of directories.
Linux dirs command Function Description
Use the dirs command to display a list of directories or, if unoptioned, the current list of directories.
Linux dirs command Syntax
dirs [Option]
The meaning of each option in the command is shown in the table.
Option | Description |
---|---|
+n |
Display the nth directory from the left, starting from 0 |
-n |
Display the nth directory from the right, starting from 0 |
-p |
One entry per line shows the directory stack |
-l |
Generate a long list, the default list format uses wavy lines to represent home directories |
-c |
Empty the directory stack by deleting all entries |
-v |
One entry per row shows the directory stack, where each entry has its index |
Linux dirs command Example
Commonly used examples
# Add a directory to the stack.
[user2@pc ~]dirs
~
[user2@pc ~] pushd -n ~/Desktop
~ ~/Desktop
[user2@pc ~]pushd -n ~/Pictures
~ ~/Pictures ~/Desktop
[user2@pc ~] pushd -n ~/bin
~ ~/bin ~/Pictures ~/Desktop
# Examples of options and parameters:
[user2@pc ~]dirs -l
/home/user2 /home/user2/bin /home/user2/Pictures /home/user2/Desktop
[user2@pc ~] dirs -p
~
~/bin
~/Pictures
~/Desktop
[user2@pc ~]dirs -v
0 ~
1 ~/bin
2 ~/Pictures
3 ~/Desktop
[user2@pc ~] dirs +2
~/Pictures
[user2@pc ~]dirs -2
~/bin
[user2@pc ~] dirs -c
[user2@pc ~]$ dirs
~
Displays a list of directories.
dirs
Output:
Display a list of directories, producing a long list
[root@rhel ~]# dirs -l
/root
Display a list of directories, one entry per line showing the directory stack
[root@rhel ~]# dirs -p
~