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,491 results
find . -type f -name \*.php | while IFS="" read i; do expand -t4 "$i" > "$i-"; mv "$i-" "$i"; done
2011-04-08 12:53:14
User: flatcap
Functions: expand find mv read
-4

Recursively find php files and replace tab characters with spaces.

Options:

"\*.php" -- replace this with the files you wish to find

"expand" -- replace tabs with spaces (use "unexpand" to replace spaces with tabs)

"-t4" -- tabs represent 4 spaces

Note: The IFS="" in the middle is to prevent 'read' from eating leading/trailing whitespace in filenames.

lsb_release -d
show 802-1w
find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -exec cat {} \;|wc -l
2011-12-01 19:58:52
User: kerim
Functions: cat find wc
-4

Count your source and header file's line numbers

For example for java change the command like this

find . -name '*.java' -exec cat {} \;|wc -l

fortune -s -c -a | cowthink -d -W 45
2009-02-16 21:45:33
User: starchox
-4

The popular fortune program telling by a cow (see sample).

- fortune

- cowsay

for i in $( find . ); do echo zipping file: $i zip $i.zip $i done
2009-04-07 20:37:49
User: archlich
Functions: echo find
-4

Note that this will not work with files with spaces or characters that need to be escaped. Feel free to leave any comments to improve upon this command, and I'll add it in.

Thanks!

alias df="df | awk 'NF == 1 {printf(\$1); next}; {print}'"
2011-04-09 06:43:51
User: MeaCulpa
Functions: alias
-4

Personally I think line wrap in default df command is annoying for scripting & seeing. So I overwrite it. Maybe more work should be done if wrapped line is over 2...

while :; do integer i=0; COL=$((RANDOM%$(tput cols))); ROW=$((RANDOM%$(tput cols))); while (( i <= COL)) do tput cup $i $ROW; echo "\033[1;34m" $(cat /dev/urandom | head -1 | cut -c1-1) 2>/dev/null; i=$(expr $i + 1); done done
echo 3 > /proc/sys/vm/drop_caches
synclient TouchPadOff=1
synclient TouchPadOff=0
scp $user@$server:$path/to/file .
echo **/* | xargs grep 'hoge'
sitepass2() {salt="this_salt";pass=`echo -n "$@"`;for i in {1..500};do pass=`echo -n $pass$salt|sha512sum`;done;echo$pass|gzip -|strings -n 1|tr -d "[:space:]"|tr -s '[:print:]' |tr '!-~' 'P-~!-O'|rev|cut -b 2-15;history -d $(($HISTCMD-1));}
2010-12-09 08:42:24
User: Soubsoub
Functions: cut gzip strings tr
Tags: Security
-4

This is a safest variation for "sitepass function" that includes a SALT over a long loop for sha512sum hash

grep -r hoge .
for f in * ; do mv -- "$f" "${f/[0-9][0-9] \- /}" ; done
2009-04-10 11:06:13
Functions: mv
-4

I have often file like this

01 - file.file

02 - file.file

03 - file.file

I rename all with this command

for f in * ; do mv -- "$f" "${f/[0-9][0-9] \- /}" ; done

then it looks like this

file.file

file.file

file.file

etc

ack hoge .
rdate -s time-A.timefreq.bldrdoc.gov
./encode.sh [ h264 | xvid | theora | mpeg4 ]
wmwave
2009-05-09 20:33:27
-4

wmwave is part of wmwave package, when launched display a small wireless link monitor on your desktop with noise, level and link power.

read enterKey
2009-12-29 00:18:32
User: bbmarek
Functions: read
Tags: bash read
-4

how to finish command or script without any output

gpg --verify file.txt.asc file.txt
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