wiki:using_aliases_in_centos
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
wiki:using_aliases_in_centos [2016/07/25 12:14] – walkeradmin | wiki:using_aliases_in_centos [2023/03/09 22:35] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Using Aliases in CentOS ====== | ====== Using Aliases in CentOS ====== | ||
+ | \\ | ||
+ | \\ | ||
+ | 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.1469445244.txt.gz · Last modified: 2023/03/09 22:35 (external edit)