Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


aliases | 4 comments | Create New Account
Click here to return to the 'aliases' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
aliases
Authored by: robh on Feb 05, '01 09:19:26AM

Another handy trick with aliases is to use !* to embed arguments inside an alias, e.g.

alias zlines 'zcat !* | wc -l'

So that the command "zlines myfile.gz" is expanded into "zcat myfile.gz | wc -l", i.e. a tool to count lines in a gz-compressed file.

Also useful for users of aliases is 'which'. This command will show you either where the command is located or what it is an alias for, e.g.

which zcat
/usr/bin/zcat

which zlines
zlines: aliased to zcat !* | wc -l

If you find aliases useful for creating shorter more memorable commands, another tip I'd give is to set up environment variables in your .tcshrc (or .cshrc) file, e.g.

setenv LOGS /Library/WebServer/Logs/
setenv WEBLOG /Library/WebServer/Logs/apache_access_log
setenv ERRLOG /Library/WebServer/Logs/apache_error_log

Then you don't need to remember where your webserver access log is (handy if you work with multiple machines where the location can vary), you can then do thing like this..

cd $LOGS
or
tail -f $WEBLOG

Note that "tcsh" will autocomplete environment variables when you hit the TAB key, e.g. if you typed "wc $WE" then hit TAB, tcsh will fill in the rest to make it "wc $WEBLOG".




[ Reply to This | # ]