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,485 results
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
97

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
114

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
emacs +400 code.py
2009-03-03 14:30:19
User: prayer
Functions: emacs
Tags: emacs
2

You may also use +line:column syntax.

zgrep "Failed password" /var/log/auth.log* | awk '{print $9}' | sort | uniq -c | sort -nr | less
2009-03-03 13:45:56
User: dbart
Functions: awk sort uniq zgrep
8

This command checks for the number of times when someone has tried to login to your server and failed. If there are a lot, then that user is being targeted on your system and you might want to make sure that user either has remote logins disabled, or has a strong password, or both. If your output has an "invalid" line, it is a summary of all logins from users that don't exist on your system.

gunzip -c /var/log/auth.log.*.gz | cat - /var/log/auth.log /var/log/auth.log.0 | grep "Invalid user" | awk '{print $8;}' | sort | uniq -c | less
vlc --one-instance --playlist-enqueue -q $(while read netcast; do wget -q $netcast -O - |grep enclosure | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p'|head -n1; done <netcast.txt)
2009-03-03 04:26:01
User: tomwsmf
Functions: read sed tr wget
1

This is a quick line to stream in the latest offerings of your favorite netcasts/podcasts. You will need to have a file named netcast.txt in the directory you run this from. This file should have one and only one of your netcast's/podcst's url per line.

When run the line grabs the offering on the top of the netcast/podcast stack and end it over , quietly, to vlc.

Since I move around computers during the day I wanted an easy way to listen to my daily dose of news and such without having to worry about downloading to whatever machine I am on. This is just a quick grab and stream of whats current.

Future plans... have the list of netcasts be read from the web. possibly an rss or such. I use greader so there might be a way to use it as the source so as not to have to muck with multiple lists

find / -name "*.jpg" -print -exec rdjpgcom '{}' ';'
2009-03-03 02:13:44
User: Williebee
Functions: find
2

Finds comments in jpg files, but I can't figure out how to exclude (in output) files without comments.

sed -i 8d ~/.ssh/known_hosts
:g!/\S/d
2009-03-02 23:58:45
User: leonza99
Tags: vim
16

This command delete all the empty lines (include the lines with space) from a file.

g = global command

\S = non-whitespace character; !\S the opposite

d = delete a range

less +G <filename>
2009-03-02 23:34:21
User: leper421
Functions: less
2

The same as typing 'less filename' then 'G' or '>' or the END key. Comes in handy with shell scripts or aliases:

alias weblog='less +G /var/log/httpd/access_log'

alias errlog='less +G /var/log/httpd/error_log'

ifconfig -a | nawk 'BEGIN {FS=" "}{RS="\n"}{ if($1~ /:/) {printf "%s ", $1}}{ if($1=="inet") {print " -- ",system("arp "$2)}}'|egrep -v "^[0-9]$"
2009-03-02 23:15:13
User: leprasmurf
Functions: ifconfig
1

Needed to get the Mac of various devices on a solaris box, but didn't have root. This command used awk to display the Network device, the IP, and the MAC a line at a time.

:set ic