Sean’s Obsessions

Sean Walberg’s blog

"cd" Tricks to Increase Your Efficiency

I was doing some work that involved moving between several directories. Remembering about pushd and popd, I googled around to try and find out how to use them properly. I found this article which was helpful, but what was even better was one of the comments talking about “cd -“.

1
2
3
4
5
6
7
8
9
10
[root@host tmp]# pwd
/tmp
[root@host tmp]# cd -
/auto/tmp/sean
[root@host sean]# pwd
/auto/tmp/sean
[root@host sean]# cd -
/tmp
[root@host tmp]# pwd
/tmp

What it does is cycle you between your last two directories. It also operates outside of the pushd/popd stack:

1
2
[root@host tmp]# dirs
/tmp

So you should still be able to use those!

Comments

I’m trying something new here. Talk to me on Twitter with the button above, please.