Alias - used to create a pseudonym for another command with, or without options.
Syntax
alias [-p] [name[=value] ...]
unalias [-a] [name ... ]
Key
-p Print the current values
-a Remove All aliases
The 'alias' command is a great way to add some customization to your command line. I've found over the years, that the more you can reduce redundant typing, the more enjoyable your shell will be. Alias allows you to trim the fat in some of your commands, especially if you like getting fancy with flags. We will consider some of the ways you can use 'alias' to make life easier.
However, I have also found that the more you rely on aliasing, the more problems you can have with ambiguity. Also, by customizing your shell too much, you can run the risk of de-standardization to the point where you are no longer proficient with foreign terminals. Like all things, when used in moderation, alias can be a great resource.
Examples:
]$ alias ls='ls -a' - update the 'ls' command to include the '-a' or 'all' flag.
]$ alias ..='cd ../' - '..' instead of having to type out the 'cd' command.
]$ alias cgrep='grep -n --color' - display line numbers / color with grep.
These are just a few choices you can make. The only downside of typing them manually is that the aliases will be wiped out when you close your session. If you would like to permanently use an alias, there are a few ways to go about it.
Method 1:
Create a file in your ~/ directory called .bash_aliases. Simply add your aliases to this file and it will run when you initialize your next session.
Method 2:
The second option is to add alias commands line by line to your .bashrc file. Depending on your OS, you may already have an rc file to edit. If not, search the web for some decent examples.
Overall, 'alias' is a powerful tool and should be used judiciously.

No comments:
Post a Comment