Custom command in linux

sometimes we don’t want to type long commands every time. we want to create scripts and run custom scripts easily. today I will show you How to create commands in Linux.

This is the command I will you how to create today, hello-command. we can type the hello command and pass one parameter when we run this command it will print hello followed by text that you insert in the parameter.

first, we create a script file name “hello-command.sh”

touch hello-command.sh

before we write a file let’s take a look at file permission. the file has read and write permission.

we will change file permission to make the file can execute. use chmod command to change permission.

chmod +x hello-command.sh

let list permission to see again, the file can have to execute permission

I like to use vscode to edit script use can use other editors you want

code hello-command.sh

the script reads an argument and prints output Hello followed by the argument we insert when running the script.

#!bin/bashecho Hello $1

test the script to make it can execute correctly.

./hello-command.sh everyone

now we can create a custom script but can’t run it everywhere. when we change the directory and run the script again. it not working.

so, we will make it can run on everywhere. first, move to the directory where we create a script and move the file to /bin and remove suffix file to look prettier when we run the command.

cd <your-directory>
sudo mv hello-command.sh /bin/hello-command

reopen your terminal and run the command again.

now, you can create your own custom script to reduce repetitive tasks and make your day more productive.

Thank you for reading & enjoy your coding 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s