How to change the CDPATH for the C shells: csh and tcsh

Previously, I have showed you how to set a new PATH for the csh and tcsh shells.

Changing the PATH or CDPATH differs from shell to shell. In this article I will show you how to change the CDPATH for the BSD C shells: csh and tcsh.

Difference between PATH and CDPATH:

You can easily exec, read and write your files and folders set in the PATH directories, but you can just cd (exec) in the directories inside the directories set in the CDPATH.

In other words, the PATH is usable with every command, while the CDPATH works only for cd.

How to set a new CDPATH:

$ set cdpath = ($cdpath /path/to/dir1/ /path/to/dir2/ /path/to/dir3/)

For the csh and tcsh shells, the delimiter is ‘space’ . $CDPATH means keeping the old CDPATH and the other paths are the new added directories in the CDPATH.

How to make the CDPATH permanently:

To make the CDPATH permanently, add this line to the ~/.tcshrc and ~/.cshrc files:

set cdpath = ($cdpath /path/to/dir1/ /path/to/dir2/ /path/to/dir3/)

If the ~/.tcshrc file does not exist, the tcsh shell will read the ~/.cshrc file.

$ echo set 'cdpath = ($cdpath /path/to/dir1/ /path/to/dir2/ /path/to/dir3/)' >> ~/.tcshrc
$ echo set 'cdpath = ($cdpath /path/to/dir1/ /path/to/dir2/ /path/to/dir3/)' >> ~/.cshrc

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

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

*

Support LinuxG via Patreon
Support LinuxG.net on Patreon!
Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!