PDA

View Full Version : HOWTO Save a few seconds of your life with alias


closet geek
November 13th, 2005, 10:31 AM
If you're a command line user like myself no doubt the hassle of typing:


sudo apt-get install package

everytime you want to grab a package causes you strife. Let aliases help.

At a shell simply type:


alias apt='sudo apt-get install'
alias remove='sudo apt-get remove'
alias search='apt-cache search'

from now on you can simply type:


apt package

to install a package.


remove package

to remove a package.

and, you've guessed it:


search package

to look for a package.

To make these aliases stick add entries for them in your .bashrc or .bash_profile files.

Of coures you don't have to use my shortcuts, perhaps you'd prefer apt-search for search it's up to you such is the power of aliases. It should be noted that 'install' is already a command in Linux hence my choice of 'apt'.

cg

lizardking
November 13th, 2005, 07:53 PM
very useful...

cool!

thnx man!

23meg
November 13th, 2005, 07:55 PM
To make these permanent you can put the alias lines to your ~/.bash_profile file.

henriquemaia
November 14th, 2005, 02:30 AM
alias apt='sudo apt-get install'
alias remove='sude apt-get remove'
alias search='apt-cache search'

You have an error there. It should be sudo. Just for the sake of not misleading Ubuntu newcomers.

Apart from that, great tip. Thanks.

closet geek
November 14th, 2005, 07:32 AM
alias apt='sudo apt-get install'
alias remove='sude apt-get remove'
alias search='apt-cache search'

You have an error there. It should be sudo. Just for the sake of not misleading Ubuntu newcomers.

Apart from that, great tip. Thanks.

Oops! It should be no great suprise I also have:


alias sude='sudo'


In my bash_profile ](*,)

cg

escobar
November 18th, 2005, 12:34 AM
If you're a command line user like myself no doubt the hassle of typing:


sudo apt-get install package

everytime you want to grab a package causes you strife. Let aliases help.

At a shell simply type:


alias apt='sudo apt-get install'
alias remove='sudo apt-get remove'
alias search='apt-cache search'

from now on you can simply type:


apt package

to install a package.


remove package

to remove a package.

and, you've guessed it:


search package

to look for a package.

To make these aliases stick add entries for them in your .bashrc or .bash_profile files.

Of coures you don't have to use my shortcuts, perhaps you'd prefer apt-search for search it's up to you such is the power of aliases. It should be noted that 'install' is already a command in Linux hence my choice of 'apt'.

cg


If you're a command line user like myself no doubt the hassle of typing:


sudo apt-get install package

everytime you want to grab a package causes you strife. Let aliases help.

At a shell simply type:


alias apt='sudo apt-get install'
alias remove='sudo apt-get remove'
alias search='apt-cache search'

from now on you can simply type:


apt package

to install a package.


remove package

to remove a package.

and, you've guessed it:


search package

to look for a package.

To make these aliases stick add entries for them in your .bashrc or .bash_profile files.

Of coures you don't have to use my shortcuts, perhaps you'd prefer apt-search for search it's up to you such is the power of aliases. It should be noted that 'install' is already a command in Linux hence my choice of 'apt'.

cg

I think I missed something. I can use the aliases after entering them into terminal, but they no longer work after reboot. Here's my .bash profile:

# .bash_profile
alias purge='sudo aptitude purge'
alias apt='sudo apt-get install'
alias edit='sudo gedit'

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi


# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

-Keep in mind I added my aliases under EVERY section of this file. When I try running any of them (ex. purge gedit) I get 'command not found'. Can someone post theirs to compare?

souled
November 18th, 2005, 02:37 AM
Hmmm... try this method. gedit .bashrc Then find this section # Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

#if [ -f ~/.bash_aliases ]; then
# . ~/.bash_aliases
#fi


Uncomment (erase the #) the last three lines of that section. Then do gedit .bash_aliases and add your aliases to that file there. Then type bash to restart bash and make it read your new aliases.

escobar
November 19th, 2005, 02:38 AM
Hmmm... try this method. gedit .bashrc Then find this section # Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

#if [ -f ~/.bash_aliases ]; then
# . ~/.bash_aliases
#fi


Uncomment (erase the #) the last three lines of that section. Then do gedit .bash_aliases and add your aliases to that file there. Then type bash to restart bash and make it read your new aliases.

Hmm, 'gedit .bashrc' pulls up:

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

Doesn't seem to match your instructions. I'm guessing I missed something else? Thanks for your help so far.

escobar
November 21st, 2005, 05:24 PM
Hmm, 'gedit .bashrc' pulls up:

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

Doesn't seem to match your instructions. I'm guessing I missed something else? Thanks for your help so far.

*bump*

souled
November 21st, 2005, 05:27 PM
I'm pretty sure you can add those three lines to your .bashrc that I had.

Or just add the whole section, just uncomment the last three lines. Leave the description commented if you decide to put it in your .bashrc.

escobar
November 21st, 2005, 06:51 PM
I'm pretty sure you can add those three lines to your .bashrc that I had.

Or just add the whole section, just uncomment the last three lines. Leave the description commented if you decide to put it in your .bashrc.


I really hate coming off like I'm slow but part of my problem was adding my aliases under ANY of these lines didn't work. I'll try again when I get home to be sure though. Thanks again.

bwog
November 24th, 2005, 05:42 PM
What happens when you want to install the package called apt?

Anyway, aliases can be tricky, especially when sudo is in the alias or in as part of a command using sudo.

bcrow
November 25th, 2005, 03:38 AM
Why not use aptitude in the alias instead of apt-get? Aptitude keeps track of which packagse are installed merely as dependencies, and when you remove the original package with aptitude remove, it removes the packages you don't need as well. Much better than having to unclutter ocasionally with deborphan or something.

oskude
November 25th, 2005, 04:18 AM
Why not use aptitude in the alias instead of apt-get? Aptitude keeps track of which packagse are installed merely as dependencies, and when you remove the original package with aptitude remove, it removes the packages you don't need as well. Much better than having to unclutter ocasionally with deborphan or something.and i thought aptitude is just a front-end for apt-get... may i remove apt-get and make a link from aptitude to apt-get ;)

yesplease
November 25th, 2005, 07:14 AM
I think that Synaptic is the best, it gives you a lot of info on the packages, dependent packages and recomended packages.

Bwog's post was about the dangers of aliasses, not about the package manager.

angrykeyboarder
November 25th, 2005, 08:43 PM
alias apt='sudo apt-get install'
alias remove='sudo apt-get remove'
alias search='apt-cache search'

I've been doing this for quite some time now. But extra-lazy person that I am, mine are:

alias agi='sudo apt-get install'
alias agr='sudo apt-get remove'
alias acs='apt-cache search'
alias agu='sudo apt-get update'
alias agg='sudo apt-get upgrade'

escobar
November 26th, 2005, 08:10 PM
I really hate coming off like I'm slow but part of my problem was adding my aliases under ANY of these lines didn't work. I'll try again when I get home to be sure though. Thanks again.

Here's my bash.rc file:

#.bashrc

#User specific aliases and functions
alias purge='sudo aptitude purge'
alias apt='sudo apt-get install'
alias edit='sudo gedit'
alias sources.list='/etc/apt/sources.list'
alias grub.lst=/boot/grub/menu.lst

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

It seemed to work fine after saving it then typing "bash" into terminal. Nothing else was required. Not sure what I was doing wrong. Thanks everyone.

The Beast.
May 8th, 2008, 02:17 AM
Thanks!!! I was really struggling with aliases. Now I got it working..............

BoHu
January 4th, 2009, 01:09 PM
alias icanhas='sudo apt-get install'