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

All commands from sorted by
Terminal - All commands - 11,592 results
echo Print text vertically|sed 's/\(.\)/\1\n/g'
grep -r --exclude-dir=.svn PATTERN PATH
2009-03-04 23:21:50
User: patko
Functions: grep
Tags: svn
8

exclude-dir option requires grep 2.5.3

stty -echo; ssh -t HOSTNAME "sudo some_command"; stty echo
2009-03-04 19:44:36
User: jmcantrell
Functions: ssh stty
Tags: ssh sudo
3

The ssh command alone will execute the sudo command remotely, but the password will be visible in the terminal as you type it. The two stty commands disable the terminal from echoing the password back to you, which makes the remote sudo act as it does locally.

find . -type f -print0 | xargs -r0 stat -c %Y\ %n | sort -rn | gawk '{sub(/.\//,"",$2); print $2}' > /tmp/playlist.m3u
2009-03-04 16:41:02
User: microft
Functions: find gawk sort stat xargs
3

I use this to generate a playlist with all the podcasts I listen to.

Ordered from most recent to older.

du | sort -n | tail -11 | head
2009-03-04 16:06:34
User: phage
Functions: du sort tail
-3

The pipe to head removes the listing of . as the largest directory.

somecommand 2>&1 >> logfile | tee -a logfile
2009-03-04 15:15:05
User: operon
Functions: tee
12

Useful for cron jobs -- all output will be logged but only errors will cause email to be sent. NB the order of "2>&1" and ">> logfile" is important, it doesn't work if you reverse them (everything goes to the logfile, nothing left for tee).

find . -type d -name DIR -print0 | xargs -r0 rm -r
2009-03-04 14:49:21
User: miguelbaldi
Functions: find rm xargs
Tags: svn cvs
-2

You can use this command to delete CVS/svn folders on given project.

find . -type f | wc -l
wget -c -v -S -T 100 --tries=0 `curl -s http://ms1.espectador.com/ podcast/espectador/la_venganza_sera_terrible.xml | grep -v xml | grep link | sed 's/]*>//g'`
2009-03-04 13:12:28
User: fmdlc
Functions: grep link sed wget
-3

This download a complete audio podcast

logs=$(find . -name *.log);for log in $logs; do cat /dev/null > $log;done
2009-03-04 10:05:48
Functions: cat find
-5

This find files of name like *.log and truncates them.

killall -USR1 dd
2009-03-04 08:30:20
User: vint
Functions: killall
Tags: dd
7

if you need see progress of long dd command, enter subj on other console

mencoder -vf rotate=1 -ovc lavc -oac copy "$1" -o "$1"-rot.avi
mencoder "$1" -ofps 23.976 -ovc lavc -oac copy -o "$1".avi
vi -R filename
2009-03-04 06:56:40
User: haivu
Functions: vi
Tags: vim
-3

The -R flag prevents you from making changes to a file, useful when you only want to view the file. This command is nicer than the 'more' or 'less' commands because for source codes, vi shows syntax highlight.

cal | grep --before-context 6 --after-context 6 --color -e " $(date +%e)" -e "^$(date +%e)"
2009-03-04 06:46:52
User: haivu
Functions: cal grep
Tags: PIM
3

Explanation:

* The date command evaluated to today's date with blank padded on the left if single digit

* The grep command search and highlight today's date

* The --before-context and --after-context flags displays up to 6 lines before and after the line containing today's date; thus completes the calendar.

I have tested this command on Mac OS X Leopard and Xubuntu 8.10

ping -i 60 -a IP_address
2009-03-04 06:21:22
User: haivu
Functions: ping
Tags: Network
99

Waiting for your server to finish rebooting? Issue the command above and you will hear a beep when it comes online. The -i 60 flag tells ping to wait for 60 seconds between ping, putting less strain on your system. Vary it to your need. The -a flag tells ping to include an audible bell in the output when a package is received (that is, when your server comes online).

ping -c 10 hostname
2009-03-04 06:14:52
User: haivu
Functions: ping
Tags: Network
-4

On Linux and Mac systems (I have not tested with other Unix systems), the ping command will keep on pinging until the user interrupts it with Ctrl+C. On Windows system, ping will execute for a number of times then quit. The -c flag on Linux and Mac will make this happen

ssh -t reachable_host ssh unreachable_host
2009-03-03 23:21:36
User: patko
Functions: ssh
Tags: ssh
119

Unreachable_host is unavailable from local network, but it's available from reachable_host's network. This command creates a connection to unreachable_host through "hidden" connection to reachable_host.

LC_ALL=fr_FR luit ssh root@remote_machine_ip
jhead -autorot *.jpg
watch -n 5 -d cat /proc/mdstat
$ grep -rl oldstring . |xargs sed -i -e 's/oldstring/newstring/'
2009-03-03 20:10:19
User: netfortius
Functions: grep sed
Tags: perl sed
25

recursively traverse the directory structure from . down, look for string "oldstring" in all files, and replace it with "newstring", wherever found

also:

grep -rl oldstring . |xargs perl -pi~ -e 's/oldstring/newstring'
xset dpms force standby
urpmf lib/blah
2009-03-03 16:21:52
User: ender_x
Tags: mandriva urpmi
1

Look for an rpm that supplies a specific file that you don't yet have installed.

extremely useful when you need something and don't know where it is.. or what its called.

note: uses grep like syntax.

for i in *.html ; do mv $i ${i%.html}.htm ; done