Skip to Content
Linux Shell Scripting Cookbook - Third Edition
book

Linux Shell Scripting Cookbook - Third Edition

by Clif Flynt, Sarath Lakshman, Shantanu Tushar
May 2017
Beginner
552 pages
28h 47m
English
Packt Publishing
Content preview from Linux Shell Scripting Cookbook - Third Edition

How to do it...

The pushd and popd commands replace cd for changing your working directory.

  1. To push and change a directory to a path, use this command:
        ~ $ pushd /var/www

Now the stack contains /var/www ~ and the current directory is changed to /var/www.

  1. Now, push the next directory path:
        /var/www $ pushd /usr/src

 Now the stack contains /usr/src/var/www ~ and the current directory is /usr/src.

You can push as many directory paths as needed.

  1. View the stack contents:
        $ dirs
        /usr/src /var/www ~ /usr/share /etc
        0           1              2  3              4      
  1. Now when you want to switch to any path in the list, number each path from 0 to n, then use the path number for which we need to switch. Consider this example:
        $ pushd +3

 Now it will rotate the stack and ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Linux Shell Scripting - Second Edition

Mastering Linux Shell Scripting - Second Edition

Mokhtar Ebrahim, Andrew Mallett

Publisher Resources

ISBN: 9781785881985