1

I have seen How do I use pushd and popd commands? , and I am aware that with pushd <dir> I would push <dir> to the directory stack, with popd I would pop the top directory from the directory stack - and with dirs -v I should be viewing/listing the directory stack; the cited post gives this example:

$ pushd /home; pushd /var; pushd log

me@myhost:/home$ dirs -v
 0  /home
 1  /var
 2  /tmp

So, I'm on:

$ echo $(cat /etc/issue; lsb_release -idcr); uname -a; bash --version | head -1
Ubuntu 14.04.5 LTS \n \l Distributor ID: Ubuntu Description: Ubuntu 14.04.5 LTS Release: 14.04 Codename: trusty
Linux MyPC 4.4.0-104-generic #127~14.04.1-Ubuntu SMP Mon Dec 11 12:44:15 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)

And I'm doing this test in a bash terminal:

user@PC:~$ cd /tmp/
user@PC:tmp$ dirs -v                                            ## just lists, no directory stack
total 32
drwx------ 2 user user 4096 Jan  5 18:22 MozillaMailnews/
prwxrwxr-x 1 user user    0 Jan  6 11:54 SciTE.22933.in|
-rw------- 1 user user    0 Jan  4 12:07 config-err-pY6fcB
drwx------ 2 user user 4096 Jan  6 00:55 firefox_user/
-rw------- 1 user user  275 Jan  6 12:07 h
drwx------ 2 user user 4096 Jan  5 15:43 mozilla_user0/
drwx------ 2 user user 4096 Jan  6 02:11 mozilla_mozillaUser0/
drwx------ 3 user user 4096 Jan  5 10:28 sni-qt_vlc_19957-mFfsIO/
drwx------ 2 user user 4096 Jan  4 12:07 ssh-Ry3s5LesiOrb/
drwx------ 6 root          root          4096 Jan  4 12:07 systemd-generator.yBhsiB/

user@PC:tmp$ pushd /tmp/ssh-Ry3s5LesiOrb/
/tmp/ssh-Ry3s5LesiOrb /tmp
user@PC:ssh-Ry3s5LesiOrb$ dirs -v                               ## again, just lists, no directory stack
total 0
srw------- 1 user user 0 Jan  4 12:07 agent.1477=

user@PC:ssh-Ry3s5LesiOrb$ pushd /tmp/sni-qt_vlc_19957-mFfsIO/
/tmp/sni-qt_vlc_19957-mFfsIO /tmp/ssh-Ry3s5LesiOrb /tmp
user@PC:sni-qt_vlc_19957-mFfsIO$ dirs -v                        ## again, just lists, no directory stack
total 4
drwxrwxr-x 2 user user 4096 Jan  5 10:28 icons/

user@PC:sni-qt_vlc_19957-mFfsIO$ popd
/tmp/ssh-Ry3s5LesiOrb /tmp
user@PC:ssh-Ry3s5LesiOrb$ dirs -v                               ## again, just lists, no directory stack
total 0
srw------- 1 user user 0 Jan  4 12:07 agent.1477=
user@PC:ssh-Ry3s5LesiOrb$ popd
/tmp

As you can see from this snippet, in the test I never got dirs -v to list/print the directory stack - it simply lists the files in the current directory similar to ls ?!

So, how can I get dirs -v to show/print/list the directory stack? Alternatively, is there another command I could use to show/print/list the directory stack in a bash terminal?

3
  • 2
    Show output of type dirs.
    – Cyrus
    Commented Jan 6, 2018 at 11:28
  • Thanks @Cyrus - since it's small, I'll post it in this comment: $ type dirs -> dirs is aliased to 'ls -lFS --color', so I get it now: grep dirs ~/.bashrc shows the alias is defined in ~/.bashrc; must I edit the ~/.bashrc, or is there another way to take care of this temporarily in the current bash session? Btw, feel free to post as an answer, I'll accept it.
    – sdaau
    Commented Jan 6, 2018 at 11:32
  • 1
    You can also ignore this alias with a leading backslash at bash's prompt: \dirs -v.
    – Cyrus
    Commented Jan 6, 2018 at 11:41

1 Answer 1

3

Comment out the alias line in your ~/.bashrc with a #.

In your current session you can use unalias dirs to remove this alias. Check again with type dirs.

2
  • Many thanks, @Cyrus - I also found that bash -c 'dirs -v' in the aliased session will also call the proper dirs (probably because in that subshell, the ~/.bashrc would not be read at all)
    – sdaau
    Commented Jan 6, 2018 at 11:40
  • Yes, bash reads ~/.bashrc only if it is an interactive shell.
    – Cyrus
    Commented Jan 6, 2018 at 11:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .