A few words of thanks would be greatly appreciated.

Create Your Own Command in Linux

Linux operating system allows users to create commands and execute them over the command line. To create a command in Linux, the first step is to create a bash script for the command. The second step is to make the command executable. This tutorial will walk you through both steps and show you how to create your own command in Linux.

Creating a Bash Script

To create a bash script, enter the following code:

#on displays the actual folder name
echo "the folder is 'pwd'"
#then the rest of the files
echo "The folder which contains files are 'ls'"

Save this file by pressing CTRL + O with Nano. Give it the name of your command.

Make the Command Executable

If you try to type the name of your bash script, you will notice that it will be executed (run).

Now, you have to modify the CHMOD of the script that you will run by typing:

chmod +x yourScript

Now, copy your script in the path, /usr/bin, like below:

cp yourscript /usr/bin/

You're all done! Run your command by typing the script name, which you moved to /usr/bin.

Image: © Jaroslav Machacek - Shutterstock.com


A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « Create Your Own Command in Linux », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).