Skip to content

Custom Linux Command with Alias

September 17, 2012

Purpose

This will explain how to create a custom command, using the alias command, which can be used in a linux terminal. This is useful if you are constantly executing the same commands such as changing to a certain directory and printing out the contents, running a script and then checking the contents of the directory again. Having a dedicated command can help to shorten such procedures.

NOTE: This command will only last as long as you are signed into the machine. If you restart or disconnect from the machine the command will no longer exist. For a permanent command look at the link in the “Also See” section.

Creating Command

$ alias {name-of-command}='{custom-command}'

Listing Commands

$ alias -p

Example Scenario

Say you want to create a command which will: Print out the current directory and the contents.

For this we will create a command called ‘printdir’

#pwd: A standard linux commancd which prints the working directory (current directory)
#ll: A standard linux command which lists the current files in a directory

$ alias printdir='pwd;ls'

Final usage when you are in the /u01 directory:

[username@c55555555 u01]$ printdir
/u01
total 14
drwxr-xr-x 7 root root 1024 Jul 10 15:55 accts
drwxr-xr-x 3 root root 1024 Jun 10 17:14 app
drwx—— 2 root root 12288 Dec 10 2010 lost+found

Also See:

https://softwaresanders.wordpress.com/2012/09/17/custom-linux-command-in-bin-directory/

Advertisements

From → Guide

6 Comments
  1. There is apparently a bundle to know about this. I consider you made some nice points in features also.

  2. Very good information. Lucky me I came across your blog by chance (stumbleupon). I have saved it for later!

  3. I like the valuable info you provide in your articles. I’ll bookmark your blog and check again here frequently. I am quite certain I will learn a lot of new stuff right here! Best of luck for the next!

  4. We’re a group of volunteers and starting a new scheme in our community. Your site offered us with valuable information to work on. You’ve done an impressive job and our whole community will be thankful to you.

Trackbacks & Pingbacks

  1. Custom Linux Command in Bin Directory « SoftwareSanders
  2. Homepage

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: