Page 1 of 5 123 ... LastLast
Results 1 to 10 of 46

Thread: HOWTO: make life easier in terminal using bash aliasing

  1. #1
    Join Date
    May 2005
    Location
    London
    Beans
    50

    HOWTO: make life easier in terminal using bash aliasing

    I prefer command line to anything else whenever it's possible. So I usually work in terminal. There is a capability in bash which enables you to define aliases for commands in order to make them easier to run or just as a matter of convenience. For instance you might want to have untgz as an alias for "tar xvfz" and simply type untgz foo.tar.gz to uncompress it. Or you might need to make the "rm" command safer by aliasing it to "rm -i" to ask you if it should be really removed in order to save you from horrible mistakes.

    First of all open a terminal and type
    Code:
    gedit .bashrc
    near the end of the file uncomment and change these lines:
    Code:
    # Define your own aliases here ...
    #if [ -f ~/.bash_aliases ]; then
    #    . ~/.bash_aliases
    #fi
    to:
    Code:
    # Define your own aliases here ...
    if [ -f ~/.bash_aliases ]; then
        . ~/.bash_aliases
    fi
    save and close the file. Now you can define your own aliases in a file named ".bash_aliases" (note the dot before the name please) in your home directory. Mine as a sample looks like this:
    Code:
    # For safety
    alias cp='cp -i'
    alias ln='ln -s'
    alias mv='mv -i'
    alias rm='rm -i'
    
    # convenience redefinitions
    alias ..='cd ..'
    alias ...='cd ...'
    alias cd..='cd ..'
    alias cd-='cd -'
    alias ls='ls -lh --color=auto'
    alias dir='ls -lh --color=auto'
    alias df="df -h"
    alias h=history
    
    alias untgz="tar -xvfz"
    alias untbz2="tar -xvfj"
    alias netstati="netstat --verbose --tcp --udp --programs --extend"
    
    # inventions!
    alias aptsource='sudo gedit /etc/apt/sources.list'
    alias penning='ssh  -L 5902:localhost:5902 myusername@myhost'
    alias wireless='sudo iwconfig eth1 essid belkin54g; sudo dhclient eth1'
    I hope that some people would join me and contribute by adding their own aliases
    Last edited by moment; June 26th, 2005 at 02:39 PM.

  2. #2
    Join Date
    Jan 2005
    Location
    Lawernce, Mass, USA
    Beans
    66

    Re: HOWTO: make life easier in terminal using bash aliasing

    F*cking AWESOME!
    I didnt even know that was possible. But then agian everything is possible with linux.
    That is very VERY neat. Thanks for that cool and neat tut.

    Ones I added so far. Will add more when I get the chance
    Code:
    alias aptU='sudo apt-get update'
    alias aptUI='sudo apt-get upgrade'
    alias aptI='sudo apt-get install'
    alias browse=nautilus
    alias sbrowse='sudo nautilus'
    I hope breezy includes these.
    Last edited by Jesus Franco; June 26th, 2005 at 02:49 PM.

  3. #3
    Join Date
    Jun 2005
    Beans
    13

    Re: HOWTO: make life easier in terminal using bash aliasing

    this is wicked m8! i new aboit aliasing but i didnt realize i could do this much with it. Simple awesome. this is going to save me so much time.

    cheers,

  4. #4
    Join Date
    Jul 2005
    Beans
    36

    Re: HOWTO: make life easier in terminal using bash aliasing

    Thanks very much for the bash aliases tips! It may be basic for advanced users, but newbies appreciate the tips.

  5. #5
    Join Date
    Apr 2005
    Location
    Not-So-Sunny Hawaii
    Beans
    Hidden!

    Re: HOWTO: make life easier in terminal using bash aliasing

    (my syntax might be wrong)

    for everything that requires sudo,

    alias synaptic='gksudo synaptic'
    alias iwconfig='sudo iwconfig'

    etc, etc, etc...

  6. #6
    Join Date
    Dec 2004
    Location
    Barcelona
    Beans
    264
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: make life easier in terminal using bash aliasing

    more...
    Code:
    # some more aliases
    alias vim='sudo vim'
    alias nano='sudo nano'
    alias up='sudo aptitude update'
    alias search='sudo aptitude search'
    alias show='sudo aptitude show'
    alias ins='sudo aptitude install'
    alias rem='sudo aptitude purge'
    alias clean='sudo aptitude clean'
    alias break='dpkg -l | grep -v ^ii'
    alias purge='sudo dpkg --purge'
    alias huerfan='sudo deborphan | sudo xargs apt-get remove -y'  (require deborphan installed)
    alias rules='sudo iptables -L -n'
    alias cd..='cd ..'
    alias repos='sudo nano /etc/apt/sources.list'
    Last edited by cutOff; July 26th, 2005 at 07:40 PM.
    Registered Linux User #371167

  7. #7
    Join Date
    Apr 2005
    Location
    Not-So-Sunny Hawaii
    Beans
    Hidden!

    Re: HOWTO: make life easier in terminal using bash aliasing

    Quote Originally Posted by cutOff
    more...
    Code:
    # some more aliases
    alias nano='sudo nano'
    alias up='sudo aptitude update'
    alias search='sudo aptitude search'
    alias show='sudo aptitude show'
    alias ins='sudo aptitude install'
    alias rem='sudo aptitude purge'
    alias clean='sudo aptitude clean'
    alias break='dpkg -l | grep -v ^ii'
    alias purge='sudo dpkg --purge'
    alias huerfan='sudo deborphan | sudo xargs apt-get remove -y'  (require deborphan installed)
    alias rules='sudo iptables -L -n'
    alias cd..='cd ..'
    alias repos='sudo nano /etc/apt/sources.list'
    replace nano with your favorite editor, of course

  8. #8
    Join Date
    May 2005
    Location
    Potsdam, NY
    Beans
    1,310
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: HOWTO: make life easier in terminal using bash aliasing

    Here is mine!

    Code:
    kyral@ArcadianUbuntu:~$ cat .bash_aliases
    alias cp='cp -i'
    alias ln='ln -s'
    alias mv='mv -i'
    alias rm='rm -i'
    alias ..='cd ..'
    alias ...='cd ...'
    alias cd..='cd ..'
    alias cd-='cd -'
    alias dir='ls -lh --color=auto'
    alias df="df -h"
    alias h=history
    alias untgz="tar -xvfz"
    alias untbz2="tar -xvfj"
    alias aptsource='sudo gedit /etc/apt/sources.list'
    alias aptU='sudo apt-get update'
    alias aptUI='sudo apt-get dist-upgrade'
    alias aptI='sudo apt-get install'
    alias aptR='sudo apt-get remove'
    alias aptS='apt-cache search'
    alias aptSh='apt-cache show'
    alias sourcebuild='sudo apt-get -b source'
    alias depbuild='sudo apt-get build-dep'
    alias debI='sudo dpkg -i'
    ArchLinux 0.8.0
    Associate Member of the Free Software Foundation

  9. #9
    Join Date
    Jul 2005
    Location
    DD / Germany
    Beans
    112
    Distro
    Ubuntu Development Release

    Re: HOWTO: make life easier in terminal using bash aliasing

    i love the quick suse style

    alias l='ls -l'

    cheers,
    .roots

  10. #10
    Join Date
    Jul 2005
    Location
    DD / Germany
    Beans
    112
    Distro
    Ubuntu Development Release

    Re: HOWTO: make life easier in terminal using bash aliasing

    sorry...double post by mistake

Page 1 of 5 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •