Favorite Unix command line aliases?
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.
Related videos on Youtube
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, 2022Comments
-
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 about 15 yearsRather 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 about 14 years+1 For alias ..='cd ..'
-
gWaldo over 13 years+1 for 'mroe'. I need to take care of my common misspellings...
-
-
Matt Simmons about 15 years+1 for ls='ls --color=auto'
-
Masood_mj about 15 years+1 - not a bad idea
-
olle about 15 yearsSorry for my ignorance, what is the difference between sudo vim and sudoedit? Is sudo edit = sudo $EDITOR ?
-
olle about 15 yearsvboxheadless should already be in your $PATH: uname; which vboxheadless Darwin /usr/bin/vboxheadless
-
Alex J about 15 yearssudoedit runs your editor under your account, rather than as root. That means you get access to your own ~/.vimrc and so on.
-
hayalci about 15 yearsFor the first one try "ack". it is a programmer's grep ;) betterthangrep.com
-
Mithin about 15 yearsls (and cd) only needs one hand...if the keymap is Dvorak! Same hand as 'Enter', for that matter.
-
Andy Lester about 15 yearsYou don't sync your home directories between the various machines? xoa.petdance.com/How_to:_Keep_your_home_directory_in_Subversion
-
Martin P. Hellwig about 15 yearsI 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 about 15 yearsthe 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 about 15 years+1: I use Tcsh too :-)
-
bedwyr almost 15 years+1: you're forgiven for using tcsh ;)
-
Zaid Amir almost 15 yearsChange it to xdg-open and it should work on any XDG-compliant desktop environment.
-
Zaid Amir almost 15 yearsIn some cases, pgrep is useful. Not the same effect, but still useful.
-
Dan Udey almost 15 yearsWell 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 almost 15 years@Dan: I thought the same. The alias really should not be called rm, but wb for wastebasket, or something similar.
-
Simon almost 15 yearsExactly! Harmless things like alias ls="ls --color=auto are fine, but changing the rm command etc.? Never.
-
Marcin almost 15 yearsshorter version, no need for awk: history | cut -f 5 -d' ' | sort | uniq -c | sort -n | tail
-
Marcin almost 15 yearsStoring 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 almost 15 years+1 for changing
sudo vi <somefile>
tosudoedit <somefile
! +more if I could -
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 over 14 yearsI prefer the much more subtle "alias vi=vi -R"
-
Muxecoid over 14 yearsOn 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 over 13 yearsHow's this differ from ack? betterthangrep.com
-
ELECON88 over 13 yearsi didnt know of ack till now. Ill give it a try.