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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Commands by rodolfoap from sorted by
Terminal - Commands by rodolfoap - 16 results
phase() { while :; do for n in E4 F#4 B4 C#5 D5 F#4 E4 C#5 B4 F#4 D5 C#5; do /usr/bin/play -qn synth $1 pluck $n; done; echo -n "[$1]"; done; }; phase 0.13 & phase 0.131 &
2017-06-14 20:29:26
User: rodolfoap
Functions: echo

The Piano Phase piece, by Steve Reich is a minimalist composition which is played on two pianos played at slightly different tempos, a task that's very difficult to accomplish by human players. The auditive effects produced by the cell displacement produce beautiful patterns. See https://en.wikipedia.org/wiki/Piano_Phase . My rendered version: https://ydor.org/SteveReich/piano_phase.mp3

Requires sox to be installed on the system.

There are multiple videos on youtube showing different approaches and experiences to this interpretation. There is also a synthesized version.

Even if Bash can behave as a powerful pianist, a simple threaded version leaves full room to several time glitches and even negative displacements, the same issues that human pianists experience when playing the piece. The older the computer, the better the chaos added to the result due to the CPU load. Apparently that's the reason Steve Reich composes pieces such as this.

Without further ado, please give a warm welcome to the Bash minimalist player on synthesized two-threaded pianos. Please turn off your cellphones.

scrypt(){ [ -n "$1" ]&&{ echo '. <(echo "$(tail -n+2 $0|base64 -d|mcrypt -dq)"); exit;'>$1.scrypt;cat $1|mcrypt|base64 >>$1.scrypt;chmod +x $1.scrypt;};}
2017-06-14 16:27:20
User: rodolfoap
Functions: cat chmod echo

This function will encrypt a bash script and will only execute it after providing the passphrase. Requires mcrypt to be installed on the system.

cat hello


case "$1" in

""|-h) echo "This is the fantastic Hello World. Try this:" $(basename $0) "[entity]" ;;

moon) echo Good night. ;;

sun) echo Good morning. ;;

world) echo "Hello, world!" ;;

*) echo Hi, $@. ;;


scrypt hello

Enter the passphrase (maximum of 512 characters)

Please use a combination of upper and lower case letters and numbers.

Enter passphrase:

Enter passphrase:

Stdin was encrypted.

cat hello.scrypt

. <(echo "$(/usr/bin/tail -n+2 $0|base64 -d|mcrypt -dq)");exit;









This is the fantastic Hello World. Try this: hello [entity]


Enter passphrase:

This is the fantastic Hello World. Try this: hello.scrypt [entity]

./hello world

Hello, world!

./hello.scrypt world

Enter passphrase:

Hello, world!

cat dictionary.txt|while read a; do echo $a|cryptsetup luksOpen /dev/sda5 sda5 $a && echo KEY FOUND: $a; done
2014-04-16 18:49:53
User: rodolfoap
Functions: cat echo read

Lost your luks passphrase? You can always bruteforce from the command line. See the sample output, a simple command using a dictionary.

for a in {p,P}{a,A,4}{s,S,5}{s,S,5}; do echo $a|cryptsetup luksOpen /dev/sda5 $a && echo KEY FOUND: $a; done
2014-04-16 18:41:50
User: rodolfoap
Functions: echo

Lost your luks passphrase? You can always bruteforce from the command line. See the sample output, a simple command for the "pass" word, using combinations of upper/lowercase or number replacement. The generated combinations are:

for a in {p,P}{a,A,4}{s,S,5}{s,S,5}; do echo $a; done








VAR=$(head -5)
2014-04-05 13:45:18
User: rodolfoap
Functions: head
Tags: read stdin head,

Reads n lines from stdin and puts the contents in a variable. Yes, I know the read command and its options, but find this logical even for one line.

read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg -d)2>/dev/null)"; exit;' && gpg -c<$S|cat >$C <(echo $H|sed s://:$(echo "$H"|wc -c):) - <(chmod +x $C)
2013-03-10 08:59:45
User: rodolfoap
Functions: cat chmod echo gpg read sed wc

(Please see sample output for usage)

Use any script name (the read command gets it) and it will be encrypted with the extension .crypt, i.e.:

myscript --> myscript.crypt

You can execute myscript.crypt only if you know the password. If you die, your script dies with you.

If you modify the startup line, be careful with the offset calculation of the crypted block (the XX string).

Not difficult to make script editable (an offset-dd piped to a gpg -d piped to a vim - piped to a gpg -c directed to script.new ), but not enough space to do it on a one liner.

Sorry for the chmod on parentheses, I dont like "-" at the end.

Thanks flatcap for the subshell abbreviation to /dev/null

echo "eval \"\$(dd if=\$0 bs=1 skip=XX 2>/dev/null|gpg -d 2>/dev/null)\"; exit" > script.secure; sed -i s:XX:$(stat -c%s script.secure): script.secure; gpg -c < script.bash >> script.secure; chmod +x script.secure
2013-03-09 11:16:48
User: rodolfoap
Functions: chmod echo gpg sed stat

(Please see sample output for usage)

script.bash is your script, which will be crypted to script.secure

script.bash --> script.secure

You can execute script.secure only if you know the password. If you die, your script dies with you.

If you modify the startup line, be careful with the offset calculation of the crypted block (the XX string).

Not difficult to make script editable (an offset-dd piped to a gpg -d piped to a vim - piped to a gpg -c directed to script.new ), but not enough space to do it on a one liner.

dd if=/dev/zero of=T bs=1024 count=10240;mkfs.ext3 -q T;E=$(echo 'read O;mount -o loop,offset=$O F /mnt;'|base64|tr -d '\n');echo "E=\$(echo $E|base64 -d);eval \$E;exit;">F;cat <(dd if=/dev/zero bs=$(echo 9191-$(stat -c%s F)|bc) count=1) <(cat T;rm T)>>F
2013-01-31 01:38:30
User: rodolfoap

This is just a proof of concept: A FILE WHICH CAN AUTOMOUNT ITSELF through a SIMPLY ENCODED script. It takes advantage of the OFFSET option of mount, and uses it as a password (see that 9191? just change it to something similar, around 9k). It works fine, mounts, gets modified, updated, and can be moved by just copying it.


The file is composed of three parts:

a) The legible script (about 242 bytes)

b) A random text fill to reach the OFFSET size (equals PASSWORD minus 242)

c) The actual filesystem

Logically, (a)+(b) = PASSWORD, that means OFFSET, and mount uses that option.

PLEASE NOTE: THIS IS NOT AN ENCRYPTED FILESYSTEM. To improve it, it can be mounted with a better encryption script and used with encfs or cryptfs. The idea was just to test the concept... with one line :)

It applies the original idea of http://www.commandlinefu.com/commands/view/7382/command-for-john-cons for encrypting the file.

The embedded bash script can be grown, of course, and the offset recalculation goes fine. I have my own version with bash --init-file to startup a bashrc with a well-defined environment, aliases, variables.

alias Z=base64&&Z=dG91Y2ggUExFQVNFX1NUT1BfQU5OT1lJTkdfQ09NTUFORExJTkVGVV9VU0VSUwo=&&$(echo $Z|Z -d)
2010-12-24 14:29:19
User: rodolfoap
Functions: alias echo
Tags: touch base64

Would create a file with a meaningful title. Dedicated to John Cons, who is annoying us users. Merry Christmas!!!

curl -s http://boards.4chan.org/wg/|sed -r 's/.*href="([^"]*).*/\1\n/g'|grep images|xargs wget
2010-12-12 06:32:19
User: rodolfoap
Functions: grep sed xargs

Im' not interested in images, but that's how I would do it.

(for FILE in $@; do echo $[100*++x/$#]; command-for-each-parameter; done)|zenity --progress --auto-close
2010-10-05 10:07:04
User: rodolfoap
Functions: echo

Shows a zenity progressbar for each file in a script, see the samble output. Works with any number, less, equal or greater than 100.

x is not initially defined. If used twice in the script, set it:


(for FILE in $@; do echo $[100*++x/$#]; command... "$FILE"; done)|zenity --progress --auto-close

pdftk in.pdf burst
2010-02-10 13:31:36
User: rodolfoap
Tags: pdftk

Simple alternative to the previous submitted one

printf "%50s\n"|tr ' ' -
2010-01-07 08:49:46
User: rodolfoap
Functions: printf tr

Better -and faster- using bash printf.

A=1;B=100;X=0;C=0;N=$[$RANDOM%$B+1];until [ $X -eq $N ];do read -p "N between $A and $B. Guess? " X;C=$(($C+1));A=$(($X<$N?$X:$A));B=$(($X>$N?$X:$B));done;echo "Took you $C tries, Einstein";
2009-12-16 13:24:23
User: rodolfoap
Functions: read
Tags: Game

Felt like I need to win the lottery, and wrote this command so I train and develop my guessing abilities.

mkdir myicons && find /usr/share/icons/ -type f | xargs cp -t myicons
2009-12-09 17:43:28
User: rodolfoap
Functions: cp find mkdir xargs
Tags: icons

Today I needed to choose an icon for an app. My simpler way: put all of /usr/share/icons in myicons folder and brows'em with nautilus. Then rm -r 'ed the entire dir.

find -mindepth 1 -maxdepth 1 -name .\*
2009-11-24 22:18:33
User: rodolfoap
Functions: find

find makes it easier, filtering . and ..

maxdepth could be removed, finding entries recursively. Removing mindepth causes . to appear