Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at

hpr1843 :: Some Bash tips

A few useful Bash features that may not be well known

<< First, < Previous, , Latest >>

Thumbnail of Dave Morriss
Hosted by Dave Morriss on 2015-08-26 is flagged as Explicit and is released under a CC-BY-SA license.
Bash, pushd, popd, dirs. 2.
The show is available on the Internet Archive at:

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:21:17

Bash Scripting.

This is an open series in which Hacker Public Radio Listeners can share their Bash scripting knowledge and experience with the community. General programming topics and Bash commands are explored along with some tutorials for the complete novice.

Today I want to talk about three Bash commands:

  • pushd
  • popd
  • dirs

These let you change directory on a Linux system (and others which support Bash) but keep a record of where you have been in a stack structure. The stack can be viewed and manipulated with these commands as well.

I have written out a moderately long set of notes about these commands and these are available here


Subscribe to the comments RSS feed.

Comment #1 posted on 2015-08-27 06:40:23 by Ken Fallon

Obsolete ?

Hi Dave,

I could never get my head around these commands, and your show has clarified them for me.

I have never been able to get a use case for this, that cannot be done using

cd -

That jumps you back to the previous directory. Running it again brings you back to where you started.


Comment #2 posted on 2015-08-28 11:49:33 by Dave Morriss

Maybe obsolescent or outmoded

As I said in the episode, I use these less than I used to, though I do still use them.

cd , cd- and cd only let you move between a given directory, the previous one and $HOME, whereas pushd and popd let you manipulate a much larger collection of directories.

If I'm connecting to a remote VPS or something I might do this:

pushd -n ~/Community_News/; pushd -n ~/Database/; pushd -n ~/IA/; pushd -n ~/content_cleaning/ dirs -v 0 ~ 1 ~/content_cleaning/ 2 ~/IA/ 3 ~/Database/ 4 ~/Community_News/

(note the '~/' at the start to make these absolute paths)

Then I might hop around between directories with for example:

pushd +4

Even this has been largely superseded by screen and tmux, I will admit.

I'm probably just old-fashioned :-)

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?