HOW TO CREATE CUSTOM COMMANDS IN LINUX.

Create your own linux commands

Pavan Chitneedi
3 min readMay 19, 2020

Method 1:

Step 1: From home directory open .bashrc file

sudo nano .bashrc

Step 2: Add a line at the bottom of the file in the following format
alias <your_custom_command_name>=‘<command_to_be_executed>’

alias socialfish=‘python3 ~/tools/SocialFish/SocialFish.py’

Step 3: Reboot and use the command

Note: For giving any command line arguments, give it right after the custom command. Example “socialfish root toor”

Method 2:

Step 1: In terminal execute the following command

$ echo ${PATH}

Step 2: Change directory to the first path in the above output.

$ cd /usr/local/bin

Note: When a command is entered “/usr/local/bin” will be first checked for the command and “/usr/bin” next and so on.

Step 3: Create a file with the custom command as the name of the file.

Example: If the custom command is socialfish, create a file with the name socialfish without any extensions.

$ sudo nano socialfish

Step 4: Paste the following code with the relevant command and save the file.

Code:
#!/bin/bash
python3 ~/tools/SocialFish/SocialFish.py root toor

Note: Provide the absolute path to the program which needs to be executed.

Step 5: Add executable permissions to the created file and the original file that needs to be executed.

$ sudo chmod +x socialfish

$ sudo chmod +x ~/tools/SocialFish/SocialFish.py

Step 6: Now, the custom command can be executed from any directory.

Step 7: In order to pass the arguments dynamically while executing the custom command, use the following code :

Code:
#!/bin/bash
python3 /root/tools/SocialFish/SocialFish.py ${*}

Note: “${*}” stores all the command line arguments as a single parameter.

Step 8: Finally, type the custom command along with the command line arguments and execute.

Step 9: To remove the custom command, delete the file created in “/usr/local/bin”.

$ sudo rm /usr/local/bin/socialfish

--

--

Pavan Chitneedi
Pavan Chitneedi

Written by Pavan Chitneedi

Cyber security enthusiast | Techie

Responses (1)