Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❀ đŸ’»
We are community of people that helps each other.

If you think you have some skills to help others

help someone and become a part of our community - List Q & A

Bash - own /custom command alias

0 contributions
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$

 

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more