Home About

Dumb Shell Tricks no.1 Navigation

Created //

Tags // shell, scripts, bash

Basic navigation around folders

I spend most of my time in the shell. Being able to move around quickly is important.

Here are the basics.

Going home

The cd command by itself will take you to your home folder.

[~/path/to/some/deep/project/src] $ cd
[~] $

This is exactly the same as cd ~.

Autocomplete

Pressing the TAB key will autocomplete folder and file names.

For example, let's say I'm in my home folder, and there's a subfolder named "projects".

If I type: cd p and then press TAB, the shell will autocomplete the folder name to "projects" for me.

Lots of commands have autocomplete.

Go to the previous folder

The cd - command will take you to the previous folder you were in.

[~/path/to/some/deep/project/src] $ cd
[~] $ cd -
[~/path/to/some/deep/project/src] $

Going back one

This is a custom one I add to my own machine. I create a shell alias for the letter "b" that navigates back one folder. For example:

[~/path/to/some/deep/project/src] $ b
[~/path/to/some/deep/project] $ b
[~/path/to/some/deep] $

I also have aliases that combine them. So b goes back one folder. bb goes back 2 folders. bbb goes back 3 folders, etc.

[~/path/to/some/deep/project/src] $ bb
[~/path/to/some/deep] $ bbb
[~/path] $

How? I add this to my ~/.bash_profile file:

alias b='cd ../'
alias bb='b;b'
alias bbb='b;b;b'
alias bbbb='b;b;b;b'

Next time you load a new shell, these aliases should be available. To load them immediately, run:

$ source ~/.bash_profile

And that's it for now...

Short and sweet... a few little basic things for people that are just starting to learn the shell.

There are lots of resources online for learning to get comfortable with the shell.

You could start here.

// ka

You might also be interested in...