Set CDPATH to ease folder navigation

CDPATH is an environment variable which tells the cd command where to look for the specified folder. By including the parent folders of commonly used locations you can access folders more easily - and without typing an entire path.

Open up your shell profile file .bashrc (Linux) or .bash_profile (Mac).

Somewhere near the bottom of the file add a line to set the CDPATH environment variable:

CDPATH=:..:~:~/data:~/projects

In order left to right this tells cd to look in:

  1. The current directory (blank; before the first :)
  2. The parent directory ..
  3. Your home directory ~
  4. Your projects directory in your home ~/projects

You can add as many folders to search as you like and these will be checked in order from left to right.

Restart your shell (close and reopen or enter restart) and then try to cd to folders in your home directory from anywhere on your filesystem with cd <foldername> and no path.

Latest features

Scroll pHAT Tetris  raspberry-pi

The Scroll pHAT is a little 11x5 (55) white LED matrix pHAT which you can control easily from a Raspberry Pi. In this project we'll squeeze a tiny-yet-playable game of Tetris onto the Scroll pHAT. More

Customize directory colors  bash

You can use the command ls --color (or an alias) to show directories with colours for folders, files, links, etc. However, you may not realise these colours can be easily configured using bashrc and a configuration file. Edit your .bashrc file (in your home directory) to include the following line ... More

Collaborate in the shell with screen (multiuser)  bash

Screen is a neat little program that allows you to use multiple virtual terminals in a single session on Unix/Linux and Mac. However, it does more than just that. It can also allow you to share your current session on a machine with another user - allowing you to collaboratively ... More

Discussion

comments powered by Disqus