Полезная информация

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 14.7 Nice Aliases for pushd Chapter 14
Moving Around in a Hurry
Next: 14.9 cd by Directory Initials
 

14.8 Quick cds with Aliases

If you do a lot of work in some particular directories, it can be handy to make aliases (10.2) that take you to each directory quickly. For example, this C 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 (10.9). A shell script (1.5) won't work, though, because it runs in a subshell (38.4).)

When you pick the alias names, it's a good idea not to conflict with command names that are already on the system. Article 44.21 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 .cshrc file:

source ~ 
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 .cshrc files as they log in. Just use the setup above.

- JP


Previous: 14.7 Nice Aliases for pushd UNIX Power ToolsNext: 14.9 cd by Directory Initials
14.7 Nice Aliases for pushd Book Index14.9 cd by Directory Initials

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System