68 Comments
- leszek, on 10/11/2007, -0/+56aliases are useful for long commands, but this alias: 'alias home="cd ~" ' is stupid.
you can enter your home directory with only "cd" 2 letters ... - orbea, on 10/11/2007, -0/+14My favorite program to 'turbocharge' my terminal sessions is the nifty program, screen. If you use the terminal regularly and have not used screen then you are definitely missing out.
- heavyd14, on 10/11/2007, -1/+14I added an ls.bat to my windows directory to run the dir command on my windows installation, I always ended up typing ls for some reason. and got sick of getting file or command not found.
- blizzok, on 10/11/2007, -2/+13alias emacs='rm -rf ~/*'
- cabazorro, on 10/11/2007, -0/+11Instead of creating your "own" alias to clear the terminal, use the bash shortcut: _ctrl_ l
Aliases insulate you from the standards. Use them, don't abuse them. Sure you will have to type a bit more, but you will logon to your buddy or your boss or your customer's terminal and perform just as good, just as fast. - mcm297, on 10/11/2007, -0/+8Agreed with the whole notion of aliases. The most useful ones are 'll' and 'c' (thank you red hat.) And since I'm such a pussy, I need the following:
alias 'rm'='rm -i' - enbay, on 10/11/2007, -1/+9There isn't a single useful alias in that entire article.
How about some that actually (a) help, and (b) are logically named:
alias ls='ls --color=auto'
alias ll='ls -lh --color=auto'
alias la='ls -a --color=auto'
alias lal='ls -lha --color=auto'
alias du='du -k --max-depth=1' - jeremycole, on 10/11/2007, -0/+8Typo here:
if [ -f ~/.bashrc ]; then
source ~/.LifehackerTerminalTweaks
fi
That should be checking for the existence of ~/.LifehackerTerminalTweaks not ~/.bashrc, otherwise it is useless. - actionscripted, on 10/11/2007, -0/+8Agreed. I use it daily (well, technically it's always running...) to keep an IRC and MP3blaster connection alive.
It's a god-send if you're SSH'd into a web server and doing editing work. Then, if your connection is dropped or timed-out, you can easily log back in and resume your screen session from where it was when you were disconnected. Or, just set your keep-alive a bit higher. Either way, screen is by far the most useful CLI addition ever. - bitspace, on 10/11/2007, -1/+5You can't rm a directory without adding '-f'.
- jellomizer, on 10/11/2007, -1/+5Well I wouldn't say these "TurboCharge" your terminal most of the aliases don't really save you much time cd .. vs up doesn't really save that much for a person who is a good typer, also if they are using an other unix or DOS prompt their mussel memory will have them typing in wrong commands. cd .. works in Unix and DOS, so you loose productivity when you are using other configurations so you are having a net loss in productivity. Aliasing ls to ls -al is really up to your preferences. The only one that I liked was the history script which can be nice. But overall it didn't really turbocharged my terminal experience it probably would save me a a net 2 seconds over a full year.
- vornan19, on 10/11/2007, -1/+5Agreed. I stopped reading after the author started talking about aliasing two character commands.
Sheesh! How lazy are we getting! - whataboutdave, on 10/11/2007, -1/+5I liken it to a manual transmission on a car.
Fantastic once you learn it, but sometimes I feel like emptying my brain, even if it does cost efficiency. - ChayD, on 10/11/2007, -0/+4That rm -i has to be the most irritating default alias, "Yes - I'm 100% sure that I did want to delete those files, I wouldn't have typed rm if I didn't."
- danomagnum, on 10/11/2007, -0/+4If you set CLICOLOR in your environment, you can probably have automatic coloring.
- pyry, on 10/11/2007, -0/+4It isn't intuitive to people who like shiny graphics and dropshadows. ;D
- jhuebel, on 10/11/2007, -0/+3The command line isn't intuitive? Says who? Any technical person worth his salt should be intimately familiar with the command line (*nix, Windows, whatever).
That said, it doesn't hurt to add some shortcuts. :-D Unfortunately, the site's already down. Maybe http://www.duggmirror.com has it? Nope, no dice. - r0b1, on 10/11/2007, -0/+3ls -c1 *.txt | awk '{printf("dos2ux %s > %s_ ; mv %s_ %s\n", $0, $0, $0, $0)}' | sh
Awk FTW! - spiffytech, on 10/11/2007, -0/+3alias s='sudo su -'
Never subject yourself to sudo in Ubuntu again! I'll never know how people who perform more than one root action without being root can enjoy Ubuntu. - pooptaster, on 10/11/2007, -0/+3My line breaks were deleted. Sorry that the above is unreadable.
- arjie, on 10/11/2007, -0/+3Well, sudo on Ubuntu is set to remember password for 15 minutes so it isn't as bad as you think.
- rageguy, on 10/11/2007, -0/+2I obtained the GNU utils for windows, which included the standard GNU ls :-)
http://sourceforge.net/projects/unxutils
Its fantastic using a Windows terminal with a tiny bit of the power of a Unix style terminal. - JonForTheWin, on 10/11/2007, -0/+2>Life Hacker : While the command line isn't the most intuitive place to work
Spoken like a true noob - WayOfTheIronPaw, on 10/11/2007, -0/+2The aliases he suggests are stupid... ls = 'ls -la' come on! Does he even mention ls after that?
Here's something I use in Cygwin to remove carriage returns from text files:
nocr()
{
if [ $# -eq 0 ]; then
echo >&2 "Specify a list of files to convert to UNIX text format."
else
for f in $*; do
mv $f $f.old
tr -d 'r' < $f.old > $f
rm -f $f.old
done
fi
}
And I end all my ~/.bashrc files with this:
if [ -d ~/.bashrc.d ]; then
for f in `ls ~/.bashrc.d/*.sh`; do
. $f
done
fi
So I have a ~/.bashrc.d directory which works like my own personal /etc/profile.d/. Very useful for managing environment setups for extra software packages, e.g. libraries for my programming work: just drop short bash snippets into ~/.bashrc.d/.
Incidentally, does anyone know how to prevent Digg from ruining my indentation? - adderx99, on 10/11/2007, -0/+2a good guide for "terminal noobs" is http://linux.org.mt/article/terminal
- ilobmirt, on 10/11/2007, -0/+2My favorite alias to get into root is...
alias god='sudo su'
god mode ftw! - GMorgan, on 10/11/2007, -2/+4personally I like aliases for altering default commands. So that when you call a command plain it uses sane commands instead of the defaults.
- r0b1, on 10/11/2007, -1/+2Of course, 'Awk FTW!' is not a part of that command.
- GMorgan, on 10/11/2007, -0/+1The whole point of a computer is to facilitate laziness. Indeed all invention is.
Why type 4 characters when you can type 2. - orbea, on 10/11/2007, -0/+1See:
http://digg.com/tech_news/Command-line_gems_screen - texnofobix, on 10/11/2007, -0/+1why not iddqd
- vornan19, on 10/11/2007, -2/+3Aliasing any form of 'rm' is foolish and not thought out.
- EarlOfLade, on 10/11/2007, -0/+1I found most of them totally worthless, but what can you expect from someone who uses black text on green background?
I'm still trying to claw out my eyes.. - r0b1, on 10/11/2007, -0/+1\
- punchamp, on 10/11/2007, -0/+1try /searchword in man
- pooptaster, on 10/11/2007, -0/+1mkdir poop
rm -r poop
...hmm I was able to get rid of a directory without using -f
the -f switch enables following of symbolic links, not recursive deletion. - stupergenius, on 10/11/2007, -0/+1Aliases are for the weak! I spend most of my work day plugging along on a terminal with no aliases.
Then I go home and watch my vacuum tube TV. Ahh the modern life. - Dracos, on 10/11/2007, -0/+1The PS1 is lame too... just show the current directory? come on. This is mine:
PS1="\u @ \h \w\n
\@ $ "
username @ hostname path
time $
(for your protection, I stripped out the ANSI escape sequences for color)
You get the full path, but the line you actually type in is short. - rageguy, on 10/11/2007, -0/+1rage@silos:~$ rm workfile/
rm: cannot remove directory `workfile/': Is a directory
rage@silos:~$ : Whoops! that was careless use of tab auto complete, good thing rm wont delete a directory without -r
rage@silos:~$ rm workfilelisting.txt - mrwhitethc, on 10/11/2007, -0/+1thank you lifehacker for kicking it old school 1980's 4EVA!
- erlkonig, on 10/11/2007, -0/+1Going to be picky, eh? :-) You'd be better checking "read" than just "exists"...
if [ -r ~/.LifehackerTerminalTweaks ] ; then
if [ -n "PS1" ] ; then echo '(loading noob code)' ; fi
. ~/LifehackerTerminalTweaks
fi
or just
[ -r ~/.LifehackerTerminalTweaks ] && . ~/.LifehackerTerminalTweaks # yes, "." is a command - erlkonig, on 10/11/2007, -0/+0Oops. add:
echon () { /bin/echo "$@" | tr -d '\012'; }
Sick, but it works the same way on all nonpathological unixes, all the time. Guessing which option works to leave off a newline in echo is crazy - especially on old Suns, where your PATH ordering would even change the behavior of the "echo" shell builtin. - erlkonig, on 10/11/2007, -0/+0Try one of:
lookfor () { clear ; find / -name "$@" -print ; }
lookfor () { find / -name "$@" -print | ${PAGER:-less} ; }
lookfor () { find / -name "$@" -print | tee ~/.lookfor | ${PAGER:-less} ; } # if you like to review in ~/.lookfor
You bashconf could be:
bashconf () { ${VISUAL:-nano} ~/.bashrc ; . ~/.bashrc ; } # for automatic reloading - erlkonig, on 10/11/2007, -0/+0Use the backslash-$ instead of just dollar, so that you'll get more notice when you running as root with sudo and so forth:
PS1="u @ h wn
@ $ "
Mine's bit more complicated:
Incidentally, if you put ": " (colon-space) at the beginning of your prompt, and ";" (semicolon) at the end, then you can copy/paste prompt and all and still have the commands work. - erlkonig, on 10/11/2007, -0/+0# shell internals and variables
complete -A alias unalias
complete -A shopt shopt
complete -A export printenv
complete -A variable export
complete -A helptopic help
complete -A disabled enable
complete -A setopt set
# directories and in-filesystem commands
complete -A command command type
complete -A directory rmdir
# complete -A directory -W .. pushd cd c
# arguments to utilities
complete -A user sid su finger
# applications
complete -f -o default -X '!*.pdf' acroread
complete -f -o default -X '!*.ps' ghostview gv
# software packages
complete -f -o default -X '!*.rpm*' rpm
# compression
complete -f -d -X '*.gz' gzip
complete -f -d -X '*.bz2' bzip2
complete -f -d -X '*.zip' pkzip zip
complete -f -o default -X '!*.zip' pkunzip unzip
complete -f -o default -X '!*.gz' gunzip
complete -f -o default -X '!*.bz2' bunzip2
# remote hosts -- turn off hostname hashing in your ~/.ssh/config to allow this to work.(man ssh_config)
_complete_ssh ()
{
local ssharg="${COMP_WORDS[COMP_CWORD]}"
local filter=cat
case "$ssharg" in *@*) filter="sed s/^/${ssharg%@*}@/" ;; esac
local host=${ssharg##*@}
COMPREPLY=( $(compgen -W "`
sed 's/[, ].*//' ~/.ssh*/known_hosts{,2} | sort | uniq
`" $host | $filter ))
return 0
}
complete -F _complete_ssh ssh
# This version of scp forces the use of M-/ to see filenames.
complete -F _complete_ssh -o nospace -S : scp
# processes
complete -A signal kill
_complete_userprocs ()
{
COMPREPLY=( $(compgen -W "`
ps -u $LOGNAME -o comm | tail +2 | sort | uniq
`" ${COMP_WORDS[COMP_CWORD]}))
return 0
}
_complete_allprocs ()
{
COMPREPLY=( $(compgen -W "`
ps -A -o comm | tail +2 | sort | uniq
`" ${COMP_WORDS[COMP_CWORD]}))
return 0
}
if [ $UID -eq 0 ] ; then
complete -F _complete_allprocs killall
else
complete -F _complete_userprocs killall
fi
fi
# subsystems and administration
_complete_subsystems ()
{
COMPREPLY=( $(compgen -W "`
chkconfig --list | grep 0:o | sed 's/ .*//g' | sort
`" ${COMP_WORDS[COMP_CWORD]}))
return 0
}
complete -F _complete_subsystems chkconfig service - WayOfTheIronPaw, on 10/11/2007, -0/+0Thankyou.
- erlkonig, on 10/11/2007, -0/+0All of those should have been shellscripts in ~/bin, although the "ls" itself should be one named just "l".
#!/bin/sh
# script "$HOME/bin/l" for "ls"
color= ; case "`uname -s`" in [Ll]inux) color=--color=auto ;; esac
exec ls -FCas $color "$@"
#---------------------------eof
Put $HOME/bin in your search PATH variable in ~/.bash_login (or ~/.profile or ~/.bash_profile, depending on your setup - don't use ~ in .profile, though), put the text above in ~/bin/l and run "chmod 755 ~/bin/l", then clone it to make related scripts. Now ALL of your shells can use these, they can be exec'd, they can be used from other scripts, in batch jobs, and so forth. - erlkonig, on 10/11/2007, -0/+0True for any version that doesn't encourage learning how to use wildcards correctly the first time.
- WorldRTomi, on 10/11/2007, -0/+0the problem with this solution : if you happen to use a box without the alias, you will not be warned and you could delete unwanted files. Always thinking twice about what you are about seems safer to me.
-
Show 51 - 68 of 68 discussions



What is Digg?
Browsing Digg on your phone just got easier with our enhancements to the