22

Since first becoming an Ubuntu user I have developed a growing list of aliases, and there are some that I cannot imagine being without. This makes me think that there are probably still tons of aliases that I haven't thought to use which could make the lives of me and fellow ubuntu users easier.

What aliases do you guys use which are:
general - they apply to lots of users
helpful - you use them often or they save a lot of time when you do use them

  • Apologies in advance if this is considered too subjective. I think it could become a good resource so I figured its worth trying. – Andy Groff Jan 12 '11 at 23:35
  • 5
    Community Wiki-fied. – Marco Ceppi Jan 12 '11 at 23:52
  • 1
    alias lsa='ls --color -l -A -hF --group-directories-first' – earthmeLon Nov 14 '16 at 19:37

10 Answers 10

11

Here are some that I like:

#Opens current directory in a file explorer
alias explore='nautilus .'

#Opens current directory in a file explorer with super user privileges
alias suexplore='sudo nautilus .'

#Opens current directory in Ubuntu's Disk Usage Analyzer GUI with super user privileges in the background
alias analyze='gksudo baobab . &'

#Opens a GUI text editor in the background. Can obviously be replaced with your favorite editor
alias text='gedit &'
#Same as above with super user privileges
alias sutext='gksudo gedit &'

#Opens a file with whatever program would open by double clicking on it in a GUI file explorer
#Usage: try someDocument.doc
alias try='gnome-open'

#lists contents of current directory with file permisions
alias ll='ls -l -sort'

#list all directories in current directories
alias ldir='ls -l | grep ^d'

#self explanatory
alias ..='cd ..'
alias ...='cd ../../'

#show aliases
alias a='echo "------------Your aliases------------";alias'
#Apply changes to aliases
alias sa='source ~/.bash_aliases;echo "Bash aliases sourced."'
#Edit Aliases
alias via='gksudo gedit ~/.bash_aliases &'
  • Sadly the dd command already exists – Benoît Legat Jul 23 '13 at 14:19
  • Yea that's a good point. Edited to ldir – Andy Groff Jul 23 '13 at 18:27
6

The alias I use most often:

alias go=gnome-open
6

These are my preferred aliases:

alias ll='ls -lAbhc'
alias l='ls -lBohc'

#History search (use: hs sometext)
alias hs='history | grep $1'

#Sudo vim
alias svim='sudo vim'

#Add extra protection against mistakes
alias rm='rm -I'

#Unrar alias
alias unrar='rar e'
  • 1
    I'm totally gonna use the history search and rm protection. Great addition! – Andy Groff Jan 13 '11 at 4:56
4

a couple of my favorites (and most heavily used!) are:

alias tgz='tar -zxvf'

and

alias tbz='tar -jxvf'
2

Here is my set from this github project: https://github.com/roubles/bash_aliases

###############################################################################
##
## Essentials
alias rm="rm -i" # Confrim remove

###############################################################################
##
## ls variations
alias la="ls -AF"                   # List all files
alias ld="ls -d */"                 # List only directories
alias l.="ls -A | egrep '^\.'"      # List only dotfiles (hidden files)
alias l1='ls -1AF'                  # List files (one line at a time)
alias ll="ls -lhAF"                 # List all file details
alias lg="ls -AF | grep"            # Grep through filenames (also see, hg)
alias lp="ls -d `pwd`/*"            # List full paths
alias lpg="ls -d `pwd`/* | grep"    # Grep through filenames but list full path
alias lt="ls -Alt"                  # Sort by time
alias ltr="ls -Altr"                # Sort by time (reverse)
alias lss="ls -AFlS"                # Sort by size
alias lsr="ls -AFlSr"               # Sort by size (reverse)

###############################################################################
##
#typos
alias vi="vim"
alias vmi="vim"
alias sl="ls"
alias pdw="pwd"

###############################################################################
##
#tar
alias tarc="tar czvf"
alias tarx="tar xzvf"
alias tart="tar tzvf"

###############################################################################
##
#history
alias hg='history | grep'

###############################################################################
##
#chmod
alias ax="chmod a+x"

###############################################################################
##
# Jump down
alias 1d="cd .."
alias 2d="cd ..;cd .."
alias 3d="cd ..;cd ..;cd .."
alias 4d="cd ..;cd ..;cd ..;cd .."
alias 5d="cd ..;cd ..;cd ..;cd ..;cd .."

###############################################################################
##
# Jump down (reverse)
alias 1up='cd /$(echo $PWD | cut -f 2 -d /)'
alias 2up='cd /$(echo $PWD | cut -f 2,3 -d /)'
alias 3up='cd /$(echo $PWD | cut -f 2,3,4 -d /)'
alias 4up='cd /$(echo $PWD | cut -f 2,3,4,5 -d /)'
alias 5up='cd /$(echo $PWD | cut -f 2,3,4,5,6 -d /)'
  • Do you find that alias ld="ls -d */" interferes with the "real" ld (linker)? – Scott Odle May 11 '17 at 16:29
1

I use 122 aliases at the moment, so I won't list all of them, but here's a short list of some useful ones:

 # Key press savers
 #  Naturally, key press saving aliases like these are really user-dependent.
 #  These are just a few examples.
alias s='sudo ' # the space allows for command name expansion.
alias g='git'
alias q='exit'

alias ls='ls --color=auto' # color
alias l='ls -F'            # classify
alias la='l -A'            # classify, hidden

alias ll='l -lh'  # human readable
alias lla='ll -A' # hidden

alias x='clear;'
alias xl='clear; l'
alias xla='clear; la'

# not really an alias, but it can be useful
cl () { cd $@ && ls -F; }

alias rs='rsync -avz --progress --fuzzy -e "ssh"'
alias rsd='rsync -avz --progress --delete-after --fuzzy -e "ssh"'

I used to have a small shell function that either changed into a directory or editted a file, depending on what was passed to it. That can be extremely useful when you go to change into a directory but decide to edit a file there instead. I wrote a little sourced shell function that does this and a little more: https://github.com/Paradoxial/fin/blob/master/forward.sh. I'm currently working on rewriting it to handle all sorts of files: https://github.com/Paradoxial/fin/blob/super-f/forwards.sh.

  • What's the use of an alias for exit? ctrl-d is already just two key presses, requires less action than q-enter. – leftaroundabout Oct 31 '16 at 21:22
1

Here is my list of alias. Few of them have already been included in others' lists.

# Very frequently used. Use: psg java
alias psg='ps aux | grep -i $1'

alias ..='cd ..'
alias ...='cd ../../'

# Updates repo cache and installs all kinds of updates
alias update='sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade'

# Frees up the cached memory
alias freemem='sync && echo 3 | sudo tee /proc/sys/vm/drop_caches'

# Useful for history searching. Use: hs java
alias hs='history | grep -i $1'
1

There is a website for this called alias.sh . There are lots of aliases defined by other users and you can add your own aliases to the website and others will rate them. You can even add some of the aliases you like to your list and use them. I even created an alias for updating the my alias list by adding this to my ~/.bashrc:

alias s-update-aliassh='curl -s https://alias.sh/user/{Your User}/alias > ~/.bash_aliases; exec bash'
0

I really like having an alias to more quickly create aliases. This is similar to how in Fish shell you can use 'function' and 'funcsave' - you don't need to open any file in a text editor.

Although I use Fish shell for partly this reason, you can make something similar in Bash:

$ echo -e "function alia { \n echo -e \"\n function \$1 { \n \$2 \n }\" >> ~/.bashrc \n }" >> ~/.bashrc

# restart shell to use
# usage: $ alia "name" "cmd"
#  e.g.: $ alia "gac" "git add -A; git commit -m \"\$1\" "
#        $ bash
#        $ gac "my commit message"
#         
#         $1 refers to a variable
#         note that $ and " characters are escaped in the alias content
0

This is one I use for backing up my PPAs.

#List all of my ppas in a text file dumpable form that can be fed into a script 
#     for re-loading them. Perfect for backup prior to an upgrade.
#Note the ppasrestore function below.  
alias lsppas="grep -RoPish '(?<=ppa.launchpad.net/)[^/]+/[^/ ]+' /etc/apt | sort -u | sed 's/^/ppa:/'"

function ppasrestore {

    for I in `cat $1`
    do 
        sudo add-apt-repository $I
    done
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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