start page | rating of books | rating of authors | reviews | copyrights

Unix Power ToolsUnix Power ToolsSearch this book

31.9. Quick cds with Aliases

If you do a lot of work in some particular directories, it can be handy to make aliases (Section 29.2) that take you to each directory quickly. For example, this Korn shell alias lets you type pwr to change to the /books/troff/pwrtools directory:

alias pwr='cd /books/troff/pwrtools'

(If your shell doesn't have aliases, you can use a shell function (Section 29.11). A shell script (Section 1.8) won't work, though, because it runs in a subshell (Section 24.4).)

When you pick the alias names, it's a good idea not to conflict with command names that are already on the system. Section 35.27 shows how to pick a new name.

If you have a lot of these directory-changing aliases, you might want to put them in a separate file named something like .cd_aliases. Then add these lines to your shell setup file (Section 3.3), like this C shell example for your .cshrc:

source Section 35.29, ~ Section 31.11

alias setcds source ~/.cd_aliases
setcds

That reads your aliases into each shell. If you edit the .cd_aliases file, you can read the new file into your shell by typing setcds from any directory.

Finally, if you're in a group of people who all work on the same directories, you could make a central alias file that everyone reads from their shell setup files as they log in. Just adapt the example above.

-- JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.