Helpful Aliases

Tagged: , ,

This topic was published by and viewed 1393 times since "". The last page revision was "".

Viewing 1 post (of 1 total)
  • Author

  • DevynCJohnson
    • Topics - 437
    • @devyncjohnson

    The alias command is a very helpful command to newbies, programmers, and professional administrators alike. The alias command creates a shortcut or alternate name for a command or set of commands. These new commands are saved in ~/.bash_aliases. Aliases could be viewed in the mind of Linux users as executable variables if one wished. Typing "alias" in a terminal will print the current aliases for the current user. To create an alias, type

    alias today="date '+%m/%d/%y'"

    Now, the user can type "today" to see the current date in the format Month/Day/Year.

    However, this alias will no longer exist when the user logs out or closes the terminal. To make an alias permanent, open ~/.bash_aliases in a text editor and paste the whole command (alias today="date '+%m/%d/%y'") on its own line in this file. Alternately, a user can perform this action in a command line by typing

    echo "alias today=\"date '+%m/%d/%y'\"" >> ~/.bash_aliases

    NOTE: Remember to escape special characters.

    This command will append the alias line to the end of the alias file.

    To remove a temporary alias that was created in a terminal, type "unalias ALIASNAME", where ALIASNAME is the alias to remove. Unalias also suppresses a permanent alias temporarily. One helpful fact to take note of is aliases (whether temporary or permanent) are not used in scripts. For instance, if a user had "today" in a script, the alias command will not execute unless the user happened to have an installed program or script function called "today".

    To permanently remove a permanent alias, remove that line via a text editor.

    The uses for aliases are limited by the user's imagination and needs. Users could make a large alias file full of many aliases that can make the terminal very easy to use.

    Some helpful alias examples are included below. A description follows each one after the pound sign. Do not paste the comments with the aliases into the alias file, unless you want the comments.

    alias bye="exit" # Users can type "bye" to exit a terminal.
    alias BYE="exit" # BASH is case-sensitive, so "bye" is different from "BYE"
    alias Exit="exit" # If a user has a bad habit of capitalizing the first letter of commands, this alias will handle that issue
    alias EXIT="exit" # This alias helps users that tend to leave caps-lock on.
    alias clr="clear" # This is a shortcut for "clear"
    alias clsh="clear; history -c; echo \"\" > ~/.bash_history; exit" # This alias command will clear the terminal, delete the history, and exit. The backslashes protect the quotes that are within the aliases coding.
    alias del="rm" # Users that are accustomed to using DOS will benefit from an alias that mimics DOS.
    alias delete="rm" # This alias allows the user to use a easier-to-remember command to remove files.
    alias copy="cp" # This alias also allows a user to use a command that is not as abstract.
    alias firefix="firefox" # Users that misspell commands often will benefit from this idea.
    alias kthxbye="exit" # This command mimics LOLCODE's exit command. Some users may find it helpful to use commands from other languages.
    alias zed="sed" # This command helps with spelling errors.
    alias ...="cd ../.." # This shortcut can save users time. The alias is three key-presses while the original requires eight.
    alias neobzr="bzr push lp:neobot" # Because I was a regular user of Bazaar and Launchpad, I used an alias to push my changes. Other Bazaar/Launchpad users can use this alias as a template for their projects. GIT, CVS, and Mercurial users can use this idea as inspiration for their version control systems.
    alias sendbeta="bzr push lp:novabot-xaiml; bzr push lp:novabot-xaiml" # To push many projects at once, add each push command separated with a semicolon.
    alias addppa="sudo add-apt-repository" # This alias can help save time and users that cannot remember the original command
    alias bitcoin="bitcoin-qt" # Have problems remembering that last part of the command or find it pointless? Well, make another alias.
    alias coffee="coffeescript" # Coffeescript users can save time by only typing "coffee". If you are still too lazy for that, try the next alias.
    alias cs="coffeescript"
    alias makepro="qmake *.pro" # Developers have many commonly typed commands. These types of commands could use some aliases.
    alias editalias="(gedit ~/.bash_aliases &)" # Opening a file manager and changing the view settings to show hidden files and then finding the alias file can all be time-consuming. Guess what? Make another time saving alias. Now, users can quickly have the file open for modifications.
    alias install="sudo apt-get install" # The command need to install software is long, so make an alias for this as well to save time.
    alias back="cd -" # To go back to the previous folder location, typing "back" will be quick to use and easy for users to remember.

    Hopefully, this article has given you aliases you can use or ideas you can latter develop.

Viewing 1 post (of 1 total)