Languages
[Edit]
EN

Bash - own /custom command alias

2 points
Created by:
marc_so
864

In this short article we will show how to create custom alias for some command in Bash in Linux.

Quick solution:

alias alias_name="command_name"

# or

alias alias_name="command_name some_parameter_1 some_parameter_2 some_parameter_n"

Pracitcal example:

john@ubuntu-pc:~/test$ alias my-ls="ls -al"
john@ubuntu-pc:~/test$ my-ls 
total 8
drwxr-xr-x  2 john john 4096 cze  8 17:30 .
drwxr-xr-x 28 john john 4096 cze  8 17:30 ..
john@ubuntu-pc:~/test$

Note: above solution will be providing alias only for current session - after login operaterion it will be necessary to create alias again.

Read next section to see how to add alias permanently.

Adding alias to user configuration example

In this section we show how to use .bashrc file to add permanently our alias to bash in our session.

1. Run following command (you can use different editor than nano):

john@ubuntu-pc:~/test$ nano ~/.bashrc

2. Paste alias line into file (you can put it at the end of the .bashrc file):

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)

# some script here...

alias my-ls="ls -al"

3. Save file changes (ctrl+o) and close editor (ctrl+x).

4. Logout and login to check if my-ls alias is working:

john@ubuntu-pc:~$ cd test 
john@ubuntu-pc:~/test$ my-ls 
total 8
drwxr-xr-x  2 john john 4096 cze  8 17:30 .
drwxr-xr-x 28 john john 4096 cze  8 17:30 ..
john@ubuntu-pc:~/test$

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - own /custom command alias
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join