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.

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.

Start Discussion

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.