Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using alias from sorted by
Terminal - Commands using alias - 203 results
alias ...='while read line; do echo -n "."; done && echo ""'
alias oath='temp=$(pbpaste) && oathtool --base32 --totp "YOUR SEED HERE" | pbcopy && sleep 3 && echo -n $temp | pbcopy'
2014-03-14 19:21:18
Functions: alias echo sleep
0

Typing a word in terminal is easier than digging your phone out, opening your two-factor authentication app and typing the code in manually.

This alias copies the one-time code to your clipboard for 3 seconds (long enough to paste it into a web form), then restores whatever was on the clipboard beforehand.

This command works on Mac. Replace pbpaste/pbcopy with your distribution's versions.

alias t__s='date "+%FT%T"'
2014-03-06 04:37:55
User: UncleLouie
Functions: alias
0

This can be easier to look at in ls output. Not as clean as +%Y%m%dT%H%M%S, but quicker to write.

alias ...="awk '{fflush(); printf \".\"}' && echo \"\""
2014-02-22 22:20:22
User: lgarron
Functions: alias
7

If you're running a command with a lot of output, this serves as a simple progress indicator.

This avoids the need to use `/dev/null` for silencing. It works for any command that outputs lines, updates live (`fflush` avoids buffering), and is simple to understand.

alias t="tee >(pbcopy)"
2014-01-24 12:41:07
User: lgarron
Functions: alias
0

Very convenient to for sending data to the clipboard for processing.

However, note that tee will affect the buffering of the output (stdout won't be update very live).

alias ?=concalc
2014-01-02 01:46:44
User: boynux
Functions: alias
0

Same functionality without using bash functions.

alias ltmux="if tmux has-session -t $USER; then tmux attach -t $USER; else tmux new -s $USER; fi"
2013-12-10 14:46:28
Functions: alias
Tags: bash alias sh tmux
0

If a session with named the same as your username already exists, then attach to it, otherwise create it

alias tasks='git grep -EI "TODO|FIXME"'
2013-10-21 23:54:46
User: lizardo
Functions: alias grep
Tags: bash git todo
0

"git grep" automatically excludes untracked files (e.g. compiler output) and files under .git directory. If no directory or file is given, it will recursively search through the current directory.

alias tasks='grep --exclude-dir=.git -rEI "TODO|FIXME" . 2>/dev/null'
2013-10-17 16:40:10
User: joepie91
Functions: alias
Tags: bash todo
5

Place this in your .bashrc (or run it once) to set the `tasks` alias. Next time you enter `tasks` into a terminal, it will give you a list of all TODO and FIXME comments in the current directory and child directories, giving you a quick overview of what you still have to do!

alias timer='export ts=$(date +%s);p='\''$(date -u -d @"$(($(date +%s)-$ts))" +"%H.%M.%S")'\'';watch -n 1 -t banner $p;eval "echo $p"'
2013-08-24 16:18:45
User: ichbins
Functions: alias banner date eval watch
Tags: timer banner
1

Starts and shows a timer. banner command is a part of the sysvbanner package. Instead of the banner an echo or figlet commands could be used. Stop the timer with Ctrl-C and elapsed time will be shown as the result.

alias 2edit='xsel -b;n=pipe$RANDOM;xdotool exec --terminator -- mousepad $n -- search --sync --onlyvisible --name $n key --window %1 ctrl+v'
2013-08-11 06:18:31
User: ichbins
Functions: alias exec
1

bash output is inserted into the clipboard, then mousepad is started and the clipboard content is pasted. xsel and xdotool needs to be installed. Instead of the mousepad any other editor can be used. I've successfully tested the Sublime Text Editor and it opens a new tab for each new paste. Check Sample output for a usage example. This command is originated from here - http://goo.gl/0q9UT4

alias rn='mkdir -p ~/.rm`pwd`; mv -v -f --backup=t -t ~/.rm`pwd` "$@"'
alias clearscrollback='clear;printf %b "\033[3J"'
alias cls='clear;ls'
2013-03-19 12:18:47
User: opexxx
Functions: alias
Tags: ls clear
0

Clear the screen and list file

alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
2013-03-19 11:45:47
User: opexxx
Functions: alias
0

Add an "alert" alias for long running commands

alias gfind='find . -print0 | xargs -0 egrep -I '
alias private_mode='unset HISTFILE && echo -e "\033[1m[\033[0m\033[4m*\033[0m\033[1m] \033[0m\033[4mprivate mode activated.\033[0m"'
2013-02-17 00:03:37
User: s__
Functions: alias echo
0

same as "unset HISTFILE" - but the advantage is that you can "tab-complete" it and when you do, you won't mistype it (which could lead to not unsetting the HISTFILE).

put the alias in the ~/.bash_profile or ~/.bashrc file in your users home directory, respawn, enjoy! :)

alias LS='find -mount -maxdepth 1 -printf "%.5m %10M %#9u:%-9g %#5U:%-5G %TF_%TR %CF_%CR %AF_%AR %#15s [%Y] %p\n" 2>/dev/null'
2013-02-06 17:54:14
User: AskApache
Functions: alias
2

This alias is super-handy for me because it quickly shows the details of each file in the current directory. The output is nice because it is sortable, allowing you to expand this basic example to do something amazing like showing you a list of the newest files, the largest files, files with bad perms, etc..

A recursive alias would be:

alias LSR='find -mount -printf "%.5m %10M %#9u:%-9g %#5U:%-5G %TF_%TR %CF_%CR %AF_%AR %#15s [%Y] %p\n" 2>/dev/null'

From: http://www.askapache.com/linux/bash_profile-functions-advanced-shell.html

alias updatedb="sudo /usr/libexec/locate.updatedb"
2013-01-21 17:46:57
User: jhyland87
Functions: alias
1

MAC OSX doesn't come with an updatedb command by default, this will emulate the updatedb thats on a typical Linux OS.

Simply add it to your ~/.bash_profile

alias locate='if [ $((`date +%s`-`eval $(stat -s /var/db/locate.database); echo $st_mtime`)) -gt 3600 ]; then echo "locate: db is too old!">/dev/stderr; sudo /usr/libexec/locate.updatedb; fi; locate -i'
2013-01-21 17:45:50
User: jhyland87
Functions: alias echo locate stat sudo
Tags: locate osx mac
0

MAC OSX doesn't come with a locate command, This will do the same thing as the locate command on a typical Linux OS.

Simply add it to your ~/.bash_profile

alias ssh-x='ssh -c arcfour,blowfish-cbc -XC'
function map() { [ -n "$1" ] && alias $1="cd `pwd`" || alias | grep "'cd "; }
alias ll='ls -lisaG'
alias emacs='vim'
alias colortest="python -c \"print('\n'.join([(' '.join([('\033[38;5;' + str((i + j)) + 'm' + str((i + j)).ljust(5) + '\033[0m') if i + j < 256 else '' for j in range(10)])) for i in range(0, 256, 10)]))\""
2012-10-26 07:43:06
User: Paaskehare
Functions: alias
1

Terminal Color tester using python, works with py2 and 3