User Tools

Site Tools


wiki:using_aliases_in_centos

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
wiki:using_aliases_in_centos [2016/07/25 08:28] walkeradminwiki:using_aliases_in_centos [2023/03/09 22:35] (current) – external edit 127.0.0.1
Line 8: Line 8:
 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. 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 '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' 
 +\\  
 +\\  
 +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 /root/.bashrc 
 +\\  
 +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 
 +                . /etc/bashrc 
 +        fi 
 +\\  
 +Now add the new alias: 
 +\\  
 +        alias showip=" ip addr |grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'" 
 +\\ 
 +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/24 brd 192.168.27.255 scope global eth0 
 +\\  
 +\\ 
wiki/using_aliases_in_centos.1469431702.txt.gz · Last modified: 2023/03/09 22:35 (external edit)