Use variable names in your shell
Tired of typing in that long directory name?
Sometimes when I am developing something I will end up
working in two separate directories that are not that
related. For example, I may be writing slides in my
directory, and when they are done I want to put the
You can save a lot of typing by creating some variables for it. So instead of
% cd ~/class/cs421/periods/course-introduction/slides/ % make slides.pdf % cp slides.pdf ~/web/cs421/slides/introduction.pdf
you could have something like…
% slides=~/class/cs421/periods/course-introduction/slides/ % web=~/web/cs421/slides/ % cd $slides % make slides.pdf % cp slides.pdf $web/introduction.pdf
If you are going to use them a lot, you can put them in your startup file.
Use subshell tab completion
Another similiar trick is to use tab completion. I'm using
will run sub-shells if you hit tab. Suppose you are in that
directory as before, and you want to access the directory
~/class/cs421/periods/recursion/slides. Yeah, you could use
but that can get tedious. But you could also type
<TAB> instead of
<ENTER>. This will run the
and paste it into your command line, leaving you with
You can then just edit the line to get what you want.
Trick three — use
zsh extension to
If you give
cd two targets in
zsh, it will treat that as a search
and replace command for your current directory name. So
cd course-introduction recursion
will do the same directory switch as above.