I am a bit confused about how dirs works. The documentation says:
dirs
With no arguments, print the contents of the directory stack. Directories are added to this stack with the
pushdcommand, and removed with thecdorpopdcommands.
Q1. I never use popd nor pushd, but I noticed that dirskeeps track of the directories where I have been (which to me means, that cd adds, not removes, directories to the stack)
Q.2 After a long session using cd, it's common for dirs to print a long list of directories, but this list prints the most recent directory first and it ends with the last directory, so if I have a long list, the screen scrolls, and I can't easily see the most recent set of directories (which are typically the ones I am most interested in).
How can I print the list of directories in reverse order?
I tried dirs | sort -r, but this does not sort the entries correctly, e.g. I get
20 /foo20/bar
2 /foo2/bar
19 ...
18
...
16
11
10
1
0
The unsorted originals look like
1 /foo/bar
2 /foo2/bar
3 ...
..
9
10
11
..
20
21
..
30
