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,621 results
alias gtasks='chromium-browser --app=https://mail.google.com/tasks/ig'
2011-12-05 22:11:00
User: Bonster
Functions: alias
-4

requires a gmail account, it opens Google tasks in a self contain window, to write your todo list and have it sync online yay =)

gpg -d file.txt.gpg -o file.txt
tail -f to.log | colorize.pl +l10:".*" &
2012-01-20 21:46:47
User: peter4512
Functions: tail
Tags: perl
-4

(follow with next command)

tail -f from.log | colorize.pl +l20:".*" &

Use with http://www.commandlinefu.com/commands/view/10031/intercept-monitor-and-manipulate-a-tcp-connection. - can use to view output of tees that send traffic to files - output will be interwoven with red for sent traffic and green for received.

get colorize.pl from http://www.flinkmann.de/71-1-Colorizepl.html

alias findstring="find . -type f -print | xargs grep $1"
for i in {21..79};do echo -e "\x$i";done | tr " " "\n" | shuf | tr -d "\n"
man <COMMAND>
2013-04-05 16:08:01
Functions: man
-4

Just type man and the name of the command you want information on followed by enter.. POW!!! there you have all you need to know on the subject.

pkill
if [[ lm = $(cat /proc/cpuinfo | grep " lm ") ]] ; then echo "64 bits" ; else echo "32 bits" ; fi
2013-02-11 22:40:46
User: agd
Functions: cat echo grep
-4

CPU flags:

rm --> 16-bit processor (real mode)

tm --> 32-bit processor (? mode)

lm --> 64-bit processor (long mode)

for FILE in $(ls); do [COMMAND]; done
2009-02-17 14:42:46
User: stinger
-4

# Small for loop, that can list files in dir, and after that executes

# [COMMAND] of your choice, usefull for example rename, move, tar etc..

# change cmd's for different results :)

yum erase `yum list installed | grep 'php'`
2009-04-13 12:58:16
Functions: grep
-4

This is useful for remove all packages that are part of a common suite.

perl -lne 'use POSIX; print strftime("%Y-%m-%d", localtime(time() - 86400));'
cat /proc/cpuinfo
2009-02-17 14:50:29
User: stinger
Functions: cat
-4

how to get full cpu info of your (linux) box

for i in `netstat -rn |grep lan |cut -c55-60 |sort |uniq`; do ifconfig $i; done
2010-01-28 17:35:20
User: Kaio
Functions: cut grep ifconfig sort
-4

HP UX doesn't have a -a switch in the ifconfig command.

This line emulates the same result shown in Solaris, AIX or Linux

psgrep() { if [ ! -z $1 ] ; then echo "Grepping for processes matching $1..." ps aux | grep -i $1 | grep -v grep else echo "!! Need name to grep for" fi }
2010-02-27 13:47:28
User: evenme
Functions: echo grep ps
Tags: grep ps
-4

Grep for a named process.

awk 'NR==linenumber' filename
echo 213.251.145.96 wikileaks.com | sudo tee -a /etc/hosts
2010-12-13 03:31:07
User: matthewbauer
Functions: echo sudo tee
-4

This one is a little bit easier for those of us that aren't always root.

fdisk -l
snmpwalk -v3 -On -u <user> -l NoAuthNoPriv -m ALL <HOST_IP> .
while true; do netstat -p |grep "tcp"|grep --color=always "/[a-z]*";sleep 1;done
2009-07-16 04:52:49
User: buffer
Functions: grep netstat
-4

The -p parameter tell the netstat to display the PID and name of the program to which each socket belongs or in digestible terms list the program using the net.Hope you know what pipe symbol means!

Presently we wish to only moniter tcp connections so we ask grep to scan for string tcp, now from the op of grep tcp we further scan for regular expression /[a-z]*.

Wonder what that means ?

If we look at the op of netstat -p we can see that the name of the application is preceded by a / ( try netstat -p ) so,now i assume application name contains only characters a to z (usually this is the case) hope now it makes some sense.Regular expression /[a-z]* means to scan a string that start with a / and contains zero or more characters from the range a-z !!. Foof .. is t

snmpwalk -v3 -On -u <user> -l AuthNoPriv -a MD5 -A <auth_password> -m ALL <HOST_IP> .
cat *
2011-12-08 05:32:14
User: bahamas10
Functions: cat
-4

no need for a for loop when cat takes multiple arguments

snmpwalk -v3 -On -u <user> -l AuthNoPriv -a SHA -A <auth_password> -m ALL <HOST_IP> .
links2 -dump http://checkip.dyndns.com | cut -d ' ' -f7
ssh -t myserver.org 'sudo ls /etc'
2013-04-09 04:23:37
User: patko
Functions: ls ssh
Tags: ssh sudo
-4

This command will ask for remote sudo password before executing a remote command.

snmpwalk -v3 -On -u <user> -l AuthPriv -a SHA -A <auth_password> -X <encryption_password> -m ALL <HOST_IP> .