Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create an alias for grep like this:

grep argX ~/myfile

where argX is a parameter and myfile is always the same. How can I do this?

share|improve this question
up vote 4 down vote accepted

Alias don't supports parameter but you can write a small script and name it i.e. "filegrep"

grep $1 /home/youruser/myfile

Copy the script to /usr/bin and you can run it with filegrep argX in the console.

share|improve this answer

aliases do not support the positional parameters so you need to create a function (in ~/.profile) and alias that function.

function grepMe(){
    grep "$1" ~/myfile

and then alias it..

alias grepAlias="grepMe"
share|improve this answer
+1. Functions are the more generalized aliases suitable for this. And just to make the message clear: you don't have to create an alias; the function name will work fine in the command line. – progo May 28 '13 at 14:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.