Site Map - skip to main content - dyslexic font - mobile - text - print

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.


hpr1843 :: Some Bash tips

A few useful Bash features that may not be well known

<< First, < Previous, Latest >>

Host Image
Hosted by Dave Morriss on 2015-08-26 is flagged as Explicit and is released under a CC-BY-SA license.
Listen in ogg, spx, or mp3 format. | Comments (2)

Part of the series: 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 http://hackerpublicradio.org/eps/hpr1843_full_shownotes.html.


Comments

Subscribe to the comments RSS feed.

Comment #1 posted on 2015-08-27T06:40:23Z 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.

Ken.

Comment #2 posted on 2015-08-28T11:49:33Z 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:
Title:
Comment:
Anti Spam Question: What does the P in HPR stand for ?
Are you a spammer →
Who hosted this show →
What does HPR mean to you ?