EN
Bash - own /custom command alias
2
points
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$