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 echo from sorted by
Terminal - Commands using echo - 1,221 results
for i in *.CR2; do dcraw -c -a -h $i | ppmtojpeg > `basename $i CR2`JPG; echo $i done; done
2013-07-25 14:58:15
User: optyler
Functions: echo
0

This command takes all CR2 files in the current directory and convert them into JPG

echo "q+werty%3D%2F%3B" | php -r "echo urldecode(file_get_contents('php://stdin'));"
2013-07-17 11:37:36
User: kartikssj
Functions: echo
Tags: urldecod PHP
0

Using PHP shell to URL decode a string.

while [ 1 ]; do echo -e "220 ProFTPD 1.3.3c Server [ProFTPD] \nFAILED FTP ATTEMPT - PORT 21" | nc -vvv -l 192.168.1.65 21 >> /var/log/honeylog.log 2>> /var/log/honeylog.log; done
2013-07-16 19:05:37
User: xmuda
Functions: echo
-1

[root@dhcppc1 windows]# cat /var/log/honeylog.log

Connection from 192.168.1.71 port 21 [tcp/ftp] accepted

Connection from 192.168.1.65 port 21 [tcp/ftp] accepted

[root@dhcppc1 windows]# nc 192.168.1.65 21

220 ProFTPD 1.3.3c Server [ProFTPD]

FAILED FTP ATTEMPT - PORT 21

*You can not run it if you have activated the ftp server.

ps aux | grep $(echo $1 | sed "s/^\(.\)/[\1]/g")
2013-07-16 10:10:51
User: opexxx
Functions: echo grep ps sed
Tags: sed grep ps
1

grep по ps aux

echo "disable" > /sys/firmware/acpi/interrupts/gpeXX
2013-07-16 03:53:20
User: m33600
Functions: echo
0

change gpeXX by the culprit you discovered on phase 1

In case of this example, the culprit is the biggest number, ie, gpe1C

/sys/firmware/acpi/interrupts/ff_gbl_lock: 0 enabled

/sys/firmware/acpi/interrupts/gpe01: 0 enabled

/sys/firmware/acpi/interrupts/gpe06: 0 enabled

/sys/firmware/acpi/interrupts/gpe17: 2 enabled

/sys/firmware/acpi/interrupts/gpe18: 0 enabled

/sys/firmware/acpi/interrupts/gpe1C: 19 enabled

This procedure,if solved this universal issue all linix distros are experimenting for more than 2 years, may be included at startup, via cron. But try first commandline.

while curl -dsL example.com 2>&1 | grep 503;do sleep 8;done;echo server up
echo 'HelloWorld!' | gpg --symmetric | base64
2013-07-06 08:30:35
User: ryanchapman
Functions: echo gpg
Tags: GPG
0

Need to encrypt something from the command line? I've used this before to encrypt passwords with a master password that was shared amongst a team.

To decrypt:

~$ echo -n 'jA0EAwMCPdknsznAww5gySL1/quqhXg6QgQkIz5abzGP5EZgTbXCFU+y6dP8ySWovytc' | base64 --decode | gpg --decrypt

gpg: CAST5 encrypted data

Enter passphrase: secret

gpg: encrypted with 1 passphrase

HelloWorld!

BEGIN=`date`; rsync -avxW /home/ /backups/home ; echo "Begin time: $BEGIN" ; echo "End time..: `date`"
2013-07-06 08:24:45
User: ryanchapman
Functions: echo rsync
Tags: rsync
0

Copies a directory structure from /home/ to /backups/home (notice that the destination does not have a trailing slash)

for i in {0..255}; do echo -e "\e[38;05;${i}m\\\e[38;05;${i}m"; done | column -c 80 -s ' '; echo -e "\e[m"
convert_path2uri () { echo -n 'file://'; echo -n "$1" | perl -pe 's/([^a-zA-Z0-9_\/.])/sprintf("%%%.2x", ord($1))/eg' ;} #convert2uri '/tmp/a b' ### convert file path to URI
2013-07-01 08:54:45
User: totti
Functions: echo file perl
Tags: encoding PATH url
1

Really helpfull when play with files having spaces an other bad name. Easy to store and access names and path in just a field while saving it in a file.

This format (URL) is directly supported by nautilus and firefox (and other browsers)

f=220;echo "int s=16e3/$f;main(i){unsigned char v[s];read(0,v,s);for(;;)putchar(v[i%s]=(v[i%s]+v[++i%s])/2);}"|gcc -x c -&&./a.out</dev/urandom|aplay -d 2
2013-06-28 14:52:53
User: tehdog
Functions: aplay echo gcc
Tags: alsa sh gcc
7

outputs a f=220Hz guitar string sound (fifth string A)

needs ALSA

while true; do curl -vsL -o /dev/null example.com 2>&1 | grep 503 > /dev/null || echo "OK: server is up."; sleep 8; done
echo -n "foo" | wc -c
for ((i=0; i>-1000; --i)); do echo "${!i}"; done
2013-05-30 02:52:46
User: liungkejin
Functions: echo
0

some numbers have strange output!

some numbers output nothing!

some numbers will kill your terminal! even logout when running in tty

but i don't know why! can anyone explain it to me?

echo $[RANDOM % 2]
echo $[RANDOM % 100] # range 0-99
2013-05-25 19:02:00
User: anapsix
Functions: echo
-2

use it to stagger cronjob or to get a random number

increase the range by replacing 100 with your own max value

ls -1 | while read file; do new_file=$(echo $file | sed s/\ /_/g); mv "$file" "$new_file"; done
for i in *.pdf; do echo --------$i-------; echo; pdftotext $i - | grep -i Yourpattern; done
2013-05-22 05:36:06
User: fangfufu
Functions: echo grep
Tags: grep pdf
0

This command is useful for searching through a whole folder worth of pdf files.

cat domainlist.txt | while read line; do echo -ne $line; whois $line | grep Expiration ; done | sed 's:Expiration Date::'
echo lowercaseword | tr '[a-z]' '[A-Z]'
git-createrepo() { repos_path='/srv/git/'; mkdir $repos_path$1; cd $repos_path$1; git init --bare; echo "Repository location: ssh://$USER@`cat /etc/HOSTNAME``pwd`"; cd -; }
2013-05-09 21:44:24
User: batandwa
Functions: cd echo init mkdir
Tags: git
-3

Creates a git repository in a predefined location.

find . -name .git -print0 | while read -d $'\0' g; do echo "$g"; cd "$g"; git gc --aggressive; cd -; done
2013-05-09 08:03:23
User: Tungmar
Functions: cd echo find read
0

git gc should be run on all git repositories every 100 commits. This will help do do so if you have many git repositories ;-)

ps -o rss= -C Chrome | (x=0; while read rss; do ((x+=$rss)); done; echo $((x/1024)))
ps -e -m -o user,pid,args,%mem,rss | grep Chrome | perl -ne 'print "$1\n" if / (\d+)$/' | ( x=0;while read line; do (( x += $line )); done; echo $((x/1024)) );
echo c > /proc/sysrq-trigger
2013-05-07 19:41:40
User: fangfufu
Functions: echo
Tags: kernel
0

Well, this is quite useful for testing if your hardware watchdog is working properly.