ISO27001:2013
Certified Supplier

FIND OUT MORE

We're an ISO27001:2013 Certified Supplier

blog-post-featured-image

A really quick and simple tip: cd - takes you back to the last directory you were in.

Here’s an example:

$ pwd
/home/kae
$ cd /var/log
$ pwd
/var/log
$ cd -
/home/kae
$ pwd
/home/kae
$]

 

Slightly more involved are the pushd and popd commands. These allow you to create a “stack” of directories with pushd, and to return to the previous level with popd:

$ pwd
/home/kae
$ pushd /usr/bin
/usr/bin ~
$ pwd
/usr/bin
$ pushd /etc
/etc /usr/bin ~
$ pwd
/etc
$ popd
/usr/bin ~
$ pwd
/usr/bin
$ popd
~
$ pwd
/home/kae
$ popd
bash: popd: directory stack empty
$

Although pushd and popd are more powerful than a simple cd -, in reality they’re more complex than most people need.

Could this Linux Tip be improved? Let us know in the comments below.

Leave a Reply

Your email address will not be published. Required fields are marked *