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.

Universal configuration monitoring and system of record for IT.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands using echo from sorted by
Terminal - Commands using echo - 1,317 results
F=136; [[ $(($F % 4)) == 0 ]] && for i in $(seq 1 $(($F/4))); do echo -n $(($F-2*($i-1))),$((2*$i-1)),$((2*$i)),$(($F-2*$i+1)),; done | sed 's/,$/\n/' || echo "Make F a multiple of 4."
2014-06-11 01:21:08
User: Kayvlim
Functions: echo sed seq

Useful if you don't have at hand the ability to automatically create a booklet, but still want to.

F is the number of pages to print. It *must* be a multiple of 4; append extra blank pages if needed.

In evince, these are the steps to print it, adapted from https://help.gnome.org/users/evince/stable/duplex-npage.html.en :

1) Click File ▸ Print.

2) Choose the General tab.

Under Range, choose Pages.

Type the numbers of the pages in this order (this is what this one-liner does for you):

n, 1, 2, n-1, n-2, 3, 4, n-3, n-4, 5, 6, n-5, n-6, 7, 8, n-7, n-8, 9, 10, n-9, n-10, 11, 12, n-11...

...until you have typed n-number of pages.

3) Choose the Page Setup tab.

- Assuming a duplex printer:

Under Layout, in the Two-side menu, select Short Edge (Flip).

- If you can only print on one side, you have to print twice, one for the odd pages and one for the even pages.

In the Pages per side option, select 2.

In the Page ordering menu, select Left to right.

4) Click Print.

NUM=-1; while NUM=`echo $NUM + 1 | bc`; do echo $NUM && sleep 1; done
2014-06-07 20:48:45
User: tomivs
Functions: echo sleep

Chronometer using the bc calculator.

col() { awk '{print $('$(echo $* | sed -e s/-/NF-/g -e 's/ /),$(/g')')}'; }
2014-06-05 18:01:31
User: tekniq
Functions: awk col echo sed

Something I do a lot is extract columns from some input where cut is not suitable because the columns are separated by not a single character but multiple spaces or tabs. So I often do things like:

... | awk '{print $7, $8}'

... which is a lot of typing, additionally slowed down when typing symbols like '{}$ ... Using the simple one-line function above makes it easier and faster:

... | col 7 8

How it works:

The one-liner defines a new function with name col

The function will execute awk, and it expects standard input (coming from a pipe or input redirection)

The function arguments are processed with sed to use them with awk: replace all spaces with ,$ so that for example 1 2 3 becomes 1,$2,$3, which is inserted into the awk command to become the well formatted shell command: awk '{print $1,$2,$3}'

Allows negative indexes to extract columns relative to the end of the line.

Credit: http://www.bashoneliners.com/oneliners/oneliner/144/

echo 'flush_all' | nc localhost 11211
echo thisIsATest | sed -E 's/([A-Z])/_\L\1/g'
for i in $(cat vulns.txt); do echo $i; rpm -qa ?changelog | grep -i $i; done
2014-04-30 16:11:14
User: sonny108
Functions: cat echo grep rpm

Found it online and could be very useful

csvcount() { for dir in $@; do echo -e "$(find $dir -name '*.csv' | wc -l)\t$dir"; done }
echo 16384 > /proc/sys/net/ipv4/neigh/default/gc_thresh1; echo 32768 > /proc/sys/net/ipv4/neigh/default/gc_thresh2; echo 65535 > /proc/sys/net/ipv4/neigh/default/gc_thresh3; echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
2014-04-25 00:18:58
User: andregyn62
Functions: echo

This command solve the problem ping: sendmsg: No buffer space available to.

for i in `grep -ri "?\|?\|?\|?\|?" * --col | cut -d: -f1 |sort -u `;do sed -i "s/?/\á/g" $i; sed -i "s/?/\é/g" $i; sed -i "s/?/\í/g" $i; sed -i "s/?/\ó/g" $i; sed -i "s/?/\ú/g" $i; echo "HTMLizing file [$i]";done
2014-04-24 11:43:36
User: linuxninja
Functions: cut echo sed sort

If we've many files containing (?, ?, ?, ?, ? ) characters instead of ?, ?,... etc,...

we can ue this simple command line running a sed command inside a for loop searching for files containing that characters.

Hope u like it! Enjoy! ;)

for file in /usr/bin/*; do pacman -Qo "$file" &> /dev/null || echo "$file"; done
2014-04-22 21:57:08
User: malathion
Functions: echo file

In this example I am returning all the files in /usr/bin that weren't put there by pacman, so that they can be moved to /usr/local/bin where they (most likely) belong.

getlunid() { lv=$(df -P $1|grep "^/dev/"|awk '{print $1}'|awk -F/ '{print $3}'); hd=$(lslv -l $lv|tail -1|awk '{print $1}');id=$(odmget -q "name like $hd AND attribute=unique_id" CuAt|grep "value ="|awk -F= '{print $2}'|tr -d '"');echo $id;}
2014-04-20 18:43:21
User: bigstupid
Functions: awk df echo grep tail tr
Tags: aix lvm SAN odm

For a given filesystem return the LUN ID. Command assumes 1:1 relationship between fs:lv:hdisk:lun which may not be the case in all environments.

: $(cal [$month $year]) ; echo $_
echo -n [email protected] | md5sum | (read hash dash ; echo "https://secure.gravatar.com/avatar/${hash}")
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








for id in `ls -1 ~/.ssh | grep -v "authorized\|known_hosts\|config\|\."` ; do echo -n "$id: " ; ssh-keygen -l -f .ssh/$id ; done
2014-04-16 14:12:20
User: drockney
Functions: echo grep id ssh-keygen

Find all private keys and dump their fingerprints.

for file in $(find . -name *.mp4); do ogv=${file%%.mp4}.ogv; if test "$file" -nt "$ogv"; then echo $file' is newer then '$ogv; ffmpeg2theora $file; fi done
echo thisIsATest | sed -r 's/([A-Z])/_\L\1/g'
2014-04-11 13:36:08
User: flatcap
Functions: echo sed
Tags: sed

Convert a camelCase string into snake_case.

To complement senorpedro's command.

echo $(sudo lshw -businfo | grep -B 1 -m 1 $(df "/path/to/file" | tail -1 | awk '{print $1}' | cut -c 6-8) | head -n 1 | awk '{print $1}' | cut -c 5- | tr ":" "-") | sudo tee /sys/bus/usb/drivers/usb/unbind
2014-04-06 12:06:29
User: tweet78
Functions: awk cut df echo grep head sudo tail tee tr

You have an external USB drive or key.

Apply this command (using the file path of anything on your device) and it will simulate the unplug of this device.

If you just want the port, just type :

echo $(sudo lshw -businfo | grep -B 1 -m 1 $(df "/path/to/file" | tail -1 | awk '{print $1}' | cut -c 6-8) | head -n 1 | awk '{print $1}' | cut -c 5- | tr ":" "-")

for i in {1..256};do p=" $i";echo -e "${p: -3} \\0$(($i/64*100+$i%64/8*10+$i%8))";done|cat -t|column -c120
2014-04-04 16:54:53
User: AskApache
Functions: cat column echo

Prints out an ascii chart using builtin bash! Then formats using cat -t and column.

The best part is:

echo -e "${p: -3} \\0$(( $i/64*100 + $i%64/8*10 + $i%8 ))";

From: http://www.askapache.com/linux/ascii-codes-and-reference.html

echo "this_is_a_test" | sed -r 's/_([a-z])/\U\1/g'
echo 1395767373016 | gawk '{print strftime("%c", ( $0 + 500 ) / 1000 )}'
find . -name '*.mp3' | sort | while read -r mp3; do echo -e "<h3>$mp3</h3>\n<audio controls src=\"$mp3\"></audio>"; done > index.html; python -m http.server
2014-03-24 15:01:49
User: hendry
Functions: echo find python read sort
Tags: audio browser

I tried a few curses based mp3 players for playing back choir practice songs for my wife.

Unfortunately none of the ones I tried were capable of scrubbing a track.

Firefox saves the day.

while read i; do [ ${#i} -gt 72 ] && echo "$i"; done < /path/to/file
2014-03-20 12:27:06
User: flatcap
Functions: echo read

Filter out lines of input that contain 72, or fewer, characters.

This uses bash only. ${#i} is the number of characters in variable i.

alias ...='while read line; do echo -n "."; done && echo ""'