Favorite Unix command line aliases?

8,042

Solution 1

function s()
{
    screen -t "$@" /usr/bin/ssh "$@"
}

Connect to a host in a new screen tab, with the device name as the tab title.

Solution 2

My favourites that haven't been mentioned so far:

alias l='ls'
alias u='cd ..'
alias uu='cd ../..'
alias uuu='cd ../../..'
alias uuuu='cd ../../../..'

I'm not normally a fan of aliases that just shorten things, but I type ls so very much, and l only needs one hand.

Solution 3

none since I can never guarantee they'll be configured on EVERY system I'll log into (as myself, root, or whoever).

Solution 4

alias ..="cd .."
alias ...="cd ../.."

# mkdir and enter it immediately thereafter
mcd()           { mkdir $1 && cd $1; }

# when entering a directory, list the contents.
cd()            { builtin cd "$@" && ls; }

Solution 5

None, I change between systems so much every day that I basically gave up on it.

Share:
8,042

Related videos on Youtube

Stefan Lasiewski
Author by

Stefan Lasiewski

Stefan Lasiewski Daddy, Linux Guy, Bicyclist, Tinkerer, Fixer & Breaker of things. I work as a Senior SYstem Engineer at the National Energy Research Scientific Computing Center (NERSC) Division at Lawrence Berkeley National Laboratory (LBNL) in Berkeley, CA. Father of 3 cute children. Yes I'm a sysadmin and a parent. Heavy user of CentOS, RHEL & FreeBSD for production services at work. I also run Ubuntu at home, for the simplicity. I'm a fan of Apache HTTP Server, Nagios & Cacti. Original proposer of unix.stackexchange.com (Yes, this proposal predated askubuntu.com, and I wish they would have merged with the Unix proposal.).

Updated on September 17, 2022

Comments

  • Stefan Lasiewski
    Stefan Lasiewski over 1 year

    What are your favorite command line aliases (bash/sh/tcsh) aliases? Here are a few of mine.

    alias lsr='ls -lrt'
    alias gon='cd $HOME/Notes'
    alias devdb='mysql -h dev --user=x --password=secret dbname'
    alias ec='rm *~'; # emacs cleanup
    alias h='history'
    alias eb='exec bash'; # Solaris sometimes defaults to sh
    alias mr='more'
    alias mroe='more'
    alias qd='echo export DISPLAY=$DISPLAY'
    alias ralias='. $HOME/.alias'; # reread aliases
    alias ,,='cd ../..'
    alias ..='cd ..'
    alias c='clear'
    
    • Alex J
      Alex J about 15 years
      Rather than passing your password in on the commandline to mysql (anyone else on the server could see it!), put the username and password in a ~/.my.cnf file, and simply specify -up. MySQL tools will pick those credentials up automatically, read mysql(1) for more info.
    • mosg
      mosg about 14 years
      +1 For alias ..='cd ..'
    • gWaldo
      gWaldo over 13 years
      +1 for 'mroe'. I need to take care of my common misspellings...
  • Matt Simmons
    Matt Simmons about 15 years
    +1 for ls='ls --color=auto'
  • Masood_mj
    Masood_mj about 15 years
    +1 - not a bad idea
  • olle
    olle about 15 years
    Sorry for my ignorance, what is the difference between sudo vim and sudoedit? Is sudo edit = sudo $EDITOR ?
  • olle
    olle about 15 years
    vboxheadless should already be in your $PATH: uname; which vboxheadless Darwin /usr/bin/vboxheadless
  • Alex J
    Alex J about 15 years
    sudoedit runs your editor under your account, rather than as root. That means you get access to your own ~/.vimrc and so on.
  • hayalci
    hayalci about 15 years
    For the first one try "ack". it is a programmer's grep ;) betterthangrep.com
  • Mithin
    Mithin about 15 years
    ls (and cd) only needs one hand...if the keymap is Dvorak! Same hand as 'Enter', for that matter.
  • Andy Lester
    Andy Lester about 15 years
    You don't sync your home directories between the various machines? xoa.petdance.com/How_to:_Keep_your_home_directory_in_Subvers‌​ion
  • Martin P. Hellwig
    Martin P. Hellwig about 15 years
    I maintain with a group of other administrators around 5k machines, most of these machines during their entire lifespan never had an remote interactive user session (all installation and configuration happens automatically), sometimes there is a wierd problem and you do have to log on. We have considered to have the user admins account to auto mount from a shared NFS partition, but for the use of it isn't worth it.
  • Decebal
    Decebal about 15 years
    the bash equivalent requires a function: del() { path=readlink -f "$1" mkdir -p $WASTE$path mv $path $WASTE$path } Its not perfect (as it creates a new dir with the filename) but it works ok. (putting in newlines is left as exercise for reader!)
  • Admin
    Admin about 15 years
    +1: I use Tcsh too :-)
  • bedwyr
    bedwyr almost 15 years
    +1: you're forgiven for using tcsh ;)
  • Zaid Amir
    Zaid Amir almost 15 years
    Change it to xdg-open and it should work on any XDG-compliant desktop environment.
  • Zaid Amir
    Zaid Amir almost 15 years
    In some cases, pgrep is useful. Not the same effect, but still useful.
  • Dan Udey
    Dan Udey almost 15 years
    Well in fairness, expecting a confirmation prompt and not getting one is just as bad as expecting it to go into a wastebasket and that not happening. There's no difference, really.
  • Simon
    Simon almost 15 years
    @Dan: I thought the same. The alias really should not be called rm, but wb for wastebasket, or something similar.
  • Simon
    Simon almost 15 years
    Exactly! Harmless things like alias ls="ls --color=auto are fine, but changing the rm command etc.? Never.
  • Marcin
    Marcin almost 15 years
    shorter version, no need for awk: history | cut -f 5 -d' ' | sort | uniq -c | sort -n | tail
  • Marcin
    Marcin almost 15 years
    Storing passwords in scripts like this is potentially dangerous, unless you got it 600. Also upon execution your password goes to history file--also potentially dangerous.
  • fxmtor
    fxmtor almost 15 years
    +1 for changing sudo vi <somefile> to sudoedit <somefile! +more if I could
  • David Mackintosh
    David Mackintosh over 14 years
    ...don't have admin/root accounts include nfs directories in its path -- when NFS is bork, so is admin/root accounts. Some of my clients insist on learning this the hard way.
  • David Mackintosh
    David Mackintosh over 14 years
    I prefer the much more subtle "alias vi=vi -R"
  • Muxecoid
    Muxecoid over 14 years
    On of my company's "shared" machines we have this: % which rm rm: aliased to echo Remove !* \?\?\? If you are really sure about deleting type /bin/rm I'm not sure how good it is for preventing real accidents though.
  • jldugger
    jldugger over 13 years
    How's this differ from ack? betterthangrep.com
  • ELECON88
    ELECON88 over 13 years
    i didnt know of ack till now. Ill give it a try.