Handy Bash Shell Aliases For Linux / Unix / MacOS
-
by cobra_admin
- 79
An bash shell alias is nothing but the shortcut to commands. The alias command allows the user to launch any command or group of commands (including options and filenames) by entering a single word. Use alias command to display a list of all defined aliases. You can add user-defined aliases to ~/.bashrc file. You can cut down typing time with these aliases, work smartly, and increase productivity at the command prompt.
This post shows how to create and use aliases including 30 practical examples of bash shell aliases.
More about bash shell aliases
The general syntax for the alias command for the bash shell is as follows:
How to list bash aliases
Type the following alias command:$ alias
Sample outputs:
alias ..='cd ..' alias amazonbackup='s3backup' alias apt-get='sudo apt-get' ...
https://googleads.g.doubleclick.net/pagead/ads?gdpr=0&us_privacy=1—&client=ca-pub-7825705102693166&output=html&h=280&adk=1370912626&adf=3362782721&pi=t.aa~a.1798617643~i.14~rp.4&w=644&fwrn=4&fwrnh=100&lmt=1672925119&num_ads=1&rafmt=1&armr=3&sem=mc&pwprc=9276298954&ad_type=text_image&format=644×280&url=https%3A%2F%2Fwww.cyberciti.biz%2Ftips%2Fbash-aliases-mac-centos-linux-unix.html&fwr=0&pra=3&rh=161&rw=644&rpe=1&resp_fmts=3&wgl=1&fa=27&uach=WyJXaW5kb3dzIiwiMTUuMC4wIiwieDg2IiwiIiwiMTA4LjAuNTM1OS4xMjUiLFtdLGZhbHNlLG51bGwsIjY0IixbWyJOb3Q_QV9CcmFuZCIsIjguMC4wLjAiXSxbIkNocm9taXVtIiwiMTA4LjAuNTM1OS4xMjUiXSxbIkdvb2dsZSBDaHJvbWUiLCIxMDguMC41MzU5LjEyNSJdXSxmYWxzZV0.&dt=1672933832107&bpp=2&bdt=6875&idt=3&shv=r20230103&mjsv=m202212010101&ptt=9&saldr=aa&abxe=1&cookie=ID%3Dac7e0204d7010890-2225af792dd900ed%3AT%3D1672928645%3ART%3D1672928645%3AS%3DALNI_MYGgTI6s5iWC4F7Ry-T8V6lporB9w&gpic=UID%3D00000b9e9e1e75bf%3AT%3D1672928645%3ART%3D1672928645%3AS%3DALNI_MZNogsSPlIbVtbpcFXLVvuv7103KQ&prev_fmts=0x0%2C644x280%2C336x600%2C331x250%2C331x250&nras=2&correlator=6693053870875&frm=20&pv=1&ga_vid=1912941346.1672928644&ga_sid=1672933831&ga_hid=980720630&ga_fc=1&u_tz=330&u_his=2&u_h=864&u_w=1536&u_ah=816&u_aw=1536&u_cd=24&u_sd=1.25&dmc=8&adx=248&ady=1921&biw=1519&bih=746&scr_x=0&scr_y=0&eid=44759875%2C44759926%2C44759842%2C31071200%2C44779794%2C44780792&oid=2&pvsid=645222771849560&tmod=1729182566&uas=1&nvt=1&ref=https%3A%2F%2Fwww.cyberciti.biz%2F&eae=0&fc=1408&brdim=0%2C0%2C0%2C0%2C1536%2C0%2C1536%2C816%2C1536%2C746&vis=1&rsz=%7C%7Cs%7C&abl=NS&fu=128&bc=31&ifi=6&uci=a!6&btvi=4&fsb=1&xpc=sUETJTQtC0&p=https%3A//www.cyberciti.biz&dtd=3663
By default alias command shows a list of aliases that are defined for the current user.
How to define or create a bash shell alias
To create the alias use the following syntax:$ alias name=value
$ alias name='command'
$ alias name='command arg1 arg2'
$ alias name='/path/to/script'
$ alias name='/path/to/script.pl arg1'
In this example, create the alias c for the commonly used clear command, which clears the screen, by typing the following command and then pressing the ENTER key:$ alias c='clear'
Then, to clear the screen, instead of typing clear, you would only have to type the letter ‘c’ and press the [ENTER] key:$ c
How to disable a bash alias temporarily
An alias can be disabled temporarily using the following syntax:## path/to/full/command ##
$ /usr/bin/clear
## call alias with a backslash ##
$ \c
## use /bin/ls command and avoid ls alias ##
$ command ls
How to delete/remove a bash alias
You need to use the command called unalias to remove aliases. Its syntax is as follows:$ unalias aliasname
$ unalias foo
In this example, remove the alias c which was created in an earlier example:$ unalias c
You also need to delete the alias from the ~/.bashrc file using a text editor (see next section).
How to make bash shell aliases permanent
The alias c remains in effect only during the current login session. Once you logs out or reboot the system the alias c will be gone. To avoid this problem, add alias to your ~/.bashrc file, enter:$ vi ~/.bashrc
The alias c for the current user can be made permanent by entering the following line:
An bash shell alias is nothing but the shortcut to commands. The alias command allows the user to launch any command or group of commands (including options and filenames) by entering a single word. Use alias command to display a list of all defined aliases. You can add user-defined aliases to ~/.bashrc file. You…
An bash shell alias is nothing but the shortcut to commands. The alias command allows the user to launch any command or group of commands (including options and filenames) by entering a single word. Use alias command to display a list of all defined aliases. You can add user-defined aliases to ~/.bashrc file. You…