DEV Community

Discussion on: How to create a alias for terminal

Collapse
 
djuber profile image
Daniel Uber

Another way to do this (which should be cross-shell portable, generally) is to save the named commands to files, instead of aliases. It's something I do by leveraging a user local ~/bin directory, that I create if it's not there, and stashing all my convenience wrapper commands there, and ensuring that comes first in my path (you'll want to set that for each shell, but once ~/bin is in your path you can use the same wrapper names in any shell).

For your examples, I would consider creating two files ~/bin/pg and ~/bin/files that just call ping and ls (the ls example probably deserves some care to handle arguments correctly).

There are of course upsides and downsides, from an efficiency standpoint the aliases are often better (they live in memory so don't need to get read as input, and don't need to fork a new shell to execute the script) but both possibilities have their strengths. Eventually, if you use the shell much, you'll end up with both local shell aliases and some standalone utility scripts, and develop some sense of which to use in your situation.