How to make alias of a linux command?

by thelma.stanton , in category: General Help , a year ago

How to make alias of a linux command?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by keegan.towne , a year ago

@thelma.stanton 

To create an alias of a Linux command, you can follow these steps:

  1. Open your terminal.
  2. Type nano ~/.bashrc command to open the .bashrc file in the nano text editor. This file is executed every time you open a new terminal window.
  3. Scroll to the bottom of the file and add the following line: alias
  4. Save the changes using Ctrl + X, then Y, and finally press Enter to confirm the changes.
  5. In order to make the changes take effect, either close the terminal and open a new one, or run the command source ~/.bashrc to reload the .bashrc file in the current terminal.


Now you can use your created alias. In our example, you can simply use ll instead of ls -l to list files and directories in long format.

by aliya.yundt , 7 months ago

@thelma.stanton 

Here's a more detailed explanation of how to create an alias for a Linux command:

  1. Open your terminal: You can open the terminal by searching for it in your applications menu or by using the shortcut Ctrl + Alt + T.
  2. Determine the command you want to create an alias for: Let's say you want to create an alias for the command ls -l to list files and directories in long format as ll.
  3. Open the .bashrc file: Type the command nano ~/.bashrc in the terminal and press Enter. This will open the .bashrc file in the nano text editor.
  4. Add the alias: Scroll to the bottom of the .bashrc file and add the following line:
1
alias ll='ls -l'


This line creates an alias named ll for the ls -l command.

  1. Save the changes: To save the changes in nano, press Ctrl + X to exit, type Y to confirm that you want to save the changes, and then press Enter to save the file.
  2. Reload the .bashrc file: To apply the changes, you can either close the terminal and open a new one, or run the following command in the terminal:
1
source ~/.bashrc


  1. Test the alias: You can now use your new alias. In this case, you can type ll in the terminal to list files and directories in long format instead of typing ls -l.


That's it! You have successfully created an alias for a Linux command. You can create aliases for other commands by following a similar process.