wiki:using_aliases_in_centos
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| wiki:using_aliases_in_centos [2016/07/25 07:06] – created walkeradmin | wiki:using_aliases_in_centos [2016/07/25 11:16] (current) – walkeradmin | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| \\ | \\ | ||
| \\ | \\ | ||
| - | grep ' | + | Aliases are a way of assinging a complex command to an easy to remember word. Looking at the command below: |
| + | \\ | ||
| + | ip addr |grep ' | ||
| + | \\ | ||
| + | This returns just the IP part of the output from an //**ip addr**// command, making the output much easier to read, however remembering and typing the command requires more effort than it saves. For this then we can create an alias. | ||
| + | \\ | ||
| + | \\ | ||
| + | I want an alias called **showip** that acutally does the same as typing ip addr |grep ' | ||
| + | \\ | ||
| + | \\ | ||
| + | You need to edit the .bash file for the logged in user who will use this alias. I am logged in as pi, so I will edit that bash file.\ | ||
| + | \\ | ||
| + | Navigate to root: | ||
| + | \\ | ||
| + | cd /root | ||
| + | \\ | ||
| + | Show the list of files: | ||
| + | \\ | ||
| + | ls -al to show file list, you will see a list of files, including one called .bashrc\\ | ||
| + | \\ | ||
| + | Edit the .bashrc file by entering: | ||
| + | \\ | ||
| + | vi / | ||
| + | \\ | ||
| + | My default .bashrc file looks like this: | ||
| + | \\ | ||
| + | # .bashrc | ||
| + | |||
| + | # User specific aliases and functions | ||
| + | |||
| + | alias rm='rm -i' | ||
| + | alias cp='cp -i' | ||
| + | alias mv='mv -i' | ||
| + | |||
| + | # Source global definitions | ||
| + | if [ -f /etc/bashrc ]; then | ||
| + | . / | ||
| + | fi | ||
| + | \\ | ||
| + | Now add the new alias: | ||
| + | \\ | ||
| + | alias showip=" | ||
| + | \\ | ||
| + | save the file and exit: | ||
| + | \\ | ||
| + | :wq | ||
| + | \\ | ||
| + | You have to restart the bash for any new aliases to work | ||
| + | \\ | ||
| + | . .bashrc | ||
| + | \\ | ||
| + | If you want to see if the alias is now listed, from the command prompt just type: | ||
| + | \\ | ||
| + | alias | ||
| + | \\ | ||
| + | You should now be able to type your new command at the command line and get an output: | ||
| + | \\ | ||
| + | showip | ||
| + | inet 127.0.0.1/8 scope host lo | ||
| + | inet 192.168.27.30/ | ||
| + | \\ | ||
| + | \\ | ||
wiki/using_aliases_in_centos.1469430414.txt.gz · Last modified: (external edit)
