Linux: How to Create Your Own Command

In this post, I will share with you ideas on how to create your own command.


One of the best examples is you need to go to a directory and display the contents in the order of edit made. To achieve this you need to issue two commands. Instead of using two commands you can complete this with a single command.

Below are the commands you can use to create your own command in UNIX or LINUX.

I want to go to my home directory and list the components inside of it.

>$ cd (home_dir)
>Srini lsdm
test1
test2
test3

In the above example, I have used two commands. One is ‘cd‘ and another one is ‘lsdm’.

The useful command is ‘alias

>$ alias name=’string’

Let me create a new command

>$ alias foo='cd (home_dir); lsdm'

Now new command is created with ‘foo’.

>$ foo
>$srini
test1
test2
test3

How to check what are the commands defined in a ‘alias-command’. The command is ‘type’

>$type foo
foo is aliased to 'cd (home_dir); lsdm'

How to nullify alias-command. The command is ‘unalias’

>$ unalias foo

Now the ‘alias-command’ foo is no longer present. So the ‘foo’ command is not available now.

How to search for the files and content in the Files

Locate – it will search the pathname of similar to what you entered in any directory.

Find – you can find a particular string in a group of directories.

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.