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 using echo from sorted by
Terminal - Commands using echo - 1,332 results
changeFolder() { if [ $# -ne 2 ]; then echo "Usage: changeFolder old new"; return; fi; old=$(pwd); folder=$(echo "$old" | sed -e "s/$1/$2/g"); if [ ! -d "$folder" ]; then echo "Folder '$folder' not found."; return; fi; echo "$old -> $folder"; cd $folder;}
2014-07-29 15:36:32
User: Dracks
Functions: cd echo sed

change the path where you are, when is executed, is usefule when you've got folders to classify something like a tags, you've got devel/dist, android/ios, etc. like:



You can change between devel/project folder to dist/project without leave project.

If somebody has a better idea to do that without replace command.

echo "import uuid\nimport sys\nsys.stdout.write(str(uuid.uuid4()))" | python
2014-07-23 07:43:01
User: tippy
Functions: echo
Tags: python uuid

piped this to pbcopy (OSX only) you got a uuid in the pasteboard

echo {-1..-5}days | xargs -n1 date +"%Y-%m-%d" -d
wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash; mv git-completion.bash ~/.git-completion.bash; echo "source ~/.git-completion.bash" > ~/.bashrc; source ~/.git-completion.bash
2014-07-22 14:21:00
User: servel333
Functions: echo mv wget

Downloads this raw script https://github.com/git/git/blob/master/contrib/completion/git-completion.bash from Github, copies it to your home directory, autoloads it in ~/.bashrc and sources it.

macdst="5873b856445f";macsrc="d2a791e1715a";pkt="d4c3b2a1020004000000000000000000ffff000001000000e3eab353fa1f 0b007400000074000000$macdst $macsrc 0842ffffffffffff";for i in {1..16}; do pkt="$pkt $macdst"; done; echo "$pkt" | xxd -r -p > magicpacket.pcap
2014-07-02 17:37:44
Functions: echo

just set macdst to the mac address of the system

you wish to wake up, the macsrc is optional but helps

use tcpreplay to broadcast or wireshark to view

ssh <user>@<ip address> $(echo wmic process where \"name like \'%<process to kill>%\'\" delete)
2014-07-02 04:41:05
User: adanisch
Functions: echo ssh

Tested on Windows 8 w/SSH, Cygwin - it can be tricky to quote if you dont use the $(..) syntax to echo it back out

echo "btrfs checksum error(s) on: " && grep "btrfs: checksum error at logical" /var/log/messages | sed -e 's/^.*\( dev .*\)\(, sector.*\)\(path\: .*\))/\t\1, \3/' | sort | uniq
echo -e '\x2Hello, folks\t!\r' | sed "y/\x2\x9\xD\x20/&#9218;&#9225;&#9229;&#9248;/"
2014-06-30 14:42:15
User: hermannsw
Functions: echo sed

Not better, but more lightweight (sed instead of perl).

Above command is reduced due to length restriction of less than 256 characters and entity encoding of "Save" command on this page. This is complete command (best without entity encoding):

echo -e '\x2Helo folks\t!\r' | sed "y/\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9\xA\xB\xC\xD\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20/&#9216;&#9217;&#9218;&#9219;&#9220;&#9221;&#9222;&#9223;&#9224;&#9225;&#9226;&#9227;&#9228;&#9229;&#9230;&#9231;&#9232;&#9233;&#9234;&#9235;&#9236;&#9237;&#9238;&#9239;&#9240;&#9241;&#9242;&#9243;&#9244;&#9245;&#9246;&#9247;&#9248;/"


echo -e "a\na\nb\nc\nd" | awk '{x[$0]++}END{for (z in x){if(x[z]==1){print z}}}'
echo "some cool message from terminal" | mail -s "test" [email protected]
echo "Dave" | grep -o "bob" | sed 's/D/f/'; echo ${PIPESTATUS[1]};
2014-06-21 04:00:53
User: davethomas11
Functions: echo grep sed

Using the $PIPESTATUS array you can get the results of a command in a sequence of commands piped together. The command above returns the result of grep -o "bob", which is exit result of 1 since no match was made.

message="I have a nice easy typing pace"; for ((i=0; i<${#message}; i++)); do echo "after 200" | tclsh; printf "${message:$i:1}"; done; echo;
echo "I am $BASH_SUBSHELL levels nested";
echo $(ifconfig) | egrep -o "en.*?inet [^ ]* " | sed 's/.*inet \(.*\)$/\1/' | tail -n +2
function google { Q="[email protected]";GOOG_URL='https://www.google.com/search?tbs=li:1&q=';AGENT="Mozilla/4.0";stream=$(curl -A "$AGENT" -skLm 10 "${GOOG_URL}${Q//\ /+}");echo "$stream" | grep -o "href=\"/url[^\&]*&amp;" | sed 's/href=".url.q=\([^\&]*\).*/\1/';}
find -type f -exec bash -c 'if ffmpeg -i "{}" 2>&1 | grep -qi h264 ; then echo "{}"; fi' \;
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 [email protected]; 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/?/\&aacute;/g" $i; sed -i "s/?/\&eacute;/g" $i; sed -i "s/?/\&iacute;/g" $i; sed -i "s/?/\&oacute;/g" $i; sed -i "s/?/\&uacute;/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! ;)