Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to run these commands very often:

sudo apt-get install <package>
sudo apt-get remove <package>

Can I make it simple like:

install <package>
remove  <package>

I think I need to write a function like this:

function install(){
sudo apt-get install <package>
}

...and then need to copy paste to some location i don't know. Can anyone tell me how can I make such an install <package> command available all the time after boot?

share|improve this question
add comment

2 Answers 2

up vote 6 down vote accepted

Use shell aliases, they won't interfere with other scripts/commands, they are only replaced when the command has been typed interactively:

alias install="sudo apt-get install"

You may place this in your shell configuration file (~/.bashrc for example) and it will be defined in all your shell sessions.

share|improve this answer
add comment

You can use $1 (and so on for Nth) to refer to the first argument passed to a function or $* to refer to all of them. The $@ format refers to all the arguments passed but will expand into separate words:

function install(){
    sudo apt-get install "$@"
}

You could then put this in your ~/.bashrc file so that it will be available every time you login.

In this case, a simple alias might also do the trick:

$ alias install="sudo apt-get install"

That can also be placed in the same file.

share|improve this answer
    
alias will be temporary ? –  mr_eclair Aug 2 '11 at 14:29
    
@mr_eclair: As I mentioned, you can place aliases in ~/.bashrc in the same way so that you have them every time you pull up a bash shell. –  Caleb Aug 2 '11 at 14:33
add comment

Your Answer

 
discard

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.