Custom Commands in your Linux or Mac

Create your own custom commands, and save a lot of time using your terminal

Terminals are the superpower of developers

I have been in love with using terminals all the time even on windows. The true love comes after I understand most of the commands and how to write Bash Scripts, and If you are not a Linux or Mac user using the terminal, you missed a lot.

How can I make my own commands?

  • Open your terminal using CTRL + ALT + T

  • sudo vim ~/.bashrc

Screenshot from 2022-05-30 17-28-14.png

if you get something else so, you should install Vim

sudo apt install vim

and run the command before

  • Go down and write your bash script click I to insert in the file write alias [your command]='[ the executable command in Linux ] '

Screenshot from 2022-05-30 17-33-40.png

then ESC and :wq Enter

if you want to make clean aliases

  • create a new file in the home ~ dir `touch .bash_aliases'
  • go into it using vim .bash_aliases
  • put your aliases there
  • save it by ESC and :wq Enter

close the current terminal to refresh your bashrc

  • open a new terminal and test your new commands

Screenshot from 2022-05-30 17-41-25.png

this is the end of the tutorial

How does it works?

when we open a terminal there's a bash script run to provide a path of everything we install, when you write code . this opens your VScode so this command is saved in the bashrc this makes a configuration for everything in the current terminal

so this script begins to execute every time you open the terminal, what if I want to print something every time a open a terminal

log to your bashrc again and write what you want using echo Hi KroKing save and restart the terminal

Screenshot from 2022-05-30 17-50-13.png

Follow for more Tricks in Linux

Did you find this article valuable?

Support Mahmoud Galal by becoming a sponsor. Any amount is appreciated!