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

All commands from sorted by
Terminal - All commands - 12,388 results
sudo pv -tpreb /path/to/source | sudo dd bs=4096 of=/path/to/destination
2017-03-01 19:11:57
Functions: dd sudo

Uses the pv utility to show progress of data transfer and an ETA until completion.

You can install pv via Homebrew on macOS

tar -zcvf archive-name.tar.gz directory-name
wait_for_this.sh; echo "wait_for_this.sh finished running" | mail -s "Job Status Update" [email protected]
rename 's/^hospital\.php\?loc=(\d{4})$/hospital_$1/' hospital.php*
gcp -r -l source/ destination/
2017-02-09 23:48:38
User: fivestones

This will move a folder and merge it with another folder which may contain duplicates. Technically it's just creating hardlinks of everything in the folder, and after it's done, delete the source (with rm -r source/ ) to complete the move. This is much faster than, for example, using rsync to merge folders which would actually copy the entire contents and so for a lot of files would take much longer.

This uses macutils gcp port of cp so it can be used on osx/MacOS. If using in linux or some unix where cp includes the ability to create links with -l you can just use cp instead of gcp.

find -wholename "*/query/*.json"
curl -s http://public-dns.info/nameserver/br.csv| cut -d, -f1 | xargs -i timeout 1 ping -c1 -w 1 {} | grep time | sed -u "s/.* from \([^:]*\).*time=\([^ ]*\).*/\2\t\1/g" | sort -n | head -n1
2017-02-02 12:00:38
User: glaudiston

http://public-dns.info gives a list of online dns servers. you need to change the country in url (br in this url) with your country code. this command need some time to ping all IP in list.

stf=$(date +%s.%N);for ((;;));do ctf=$( date +%s.%N );echo -en "\r$(date -u -d "0 $ctf sec - $stf sec" "+%H:%M:%S.%N")";done
stf=$(date +%s.%N);st=${stf/.*/};sn=%{stf/*./};for ((;;));do ctf=$( date +%s.%N );ct=${ctf/.*/};cn=${ctf/*./}; dtf=$(echo "scale=3; $ctf-$stf" | bc); dt=${dtf/.*/}; dt=${dt:=0};echo -en "\r$(date -u -d @$dt "+%H:%M:%S.${dtf/*./}")";done
stf=$(date +%s.%N);st=${stf/.*/};sn=%{stf/*./};for ((;;));do ctf=$( date +%s.%N );ct=${ctf/.*/};cn=${ctf/*./}; echo -en "\r$(echo "scale=3; $ctf-$stf" | bc)";done
2017-01-26 13:20:30
User: glaudiston
Functions: date echo
Tags: chronometer

A way for tracking times in bash

favorite --add myhost 'ssh [email protected]'
2017-01-23 18:15:03
User: djangofan
Tags: history

Command 'favorite' to store your favorite commands from history.

find . -name "node_modules" -exec rm -rf '{}' \;
ex -c '1,$-1000d' -c 'wq' file
iw dev ath0 station dump
2017-01-09 00:50:49
Tags: wireless

When the wireless card is in AP mode, list the users which are connected to the network.

It uses the new nl80211 based CLI configuration utility for wireless devices.

It can be used, for example, in a dd-wrt based router through a telnet session to obtain client information.

git push --set-upstream origin master
2017-01-09 00:32:14
Tags: git

After cloning an empty repository on the client ("git clone" just after "git init", for instance), "git push" fails.

In order to be able to push to this repository for the first time, you need to run the above command. It will link your local "master" branch to the "master" branch in the origin server, and push the changes.

This is only necessary only for the first push; after that, you can use just the commands "git push" or "git pull" in order to do this operations.

tr -d '\r' < vmargs.txt | tr '\n' ' '
2016-12-31 18:20:03
User: wytten12
Functions: tr

Read vmargs.txt, which is a text file that could either be DOS-style (\r\n) or UNIX-style (\n) line endings and join the lines with a space separator. Can this be shortened/made more elegant?

ftagmarks(){ jq -r --arg t "$1" '.children[] as $i|if $i.root == "tagsFolder" then ([$i.children[] as $j|{title: ($j.title), urls: [$j.children[].uri]}]) else empty end|.[] as $k|if ($k.title|contains($t)) then $k.urls else empty end|.[]?' "$2"; }
2016-12-24 15:12:04
User: qwertyroot
Functions: as

# Usage: ftagmarks TAG BOOKMARKS.JSON

ftagmarks Bash ~/.mozilla/firefox/*.default/bookmarkbackups/bookmarks-*.json

Tag can be partial matching, e.g. input 'Bas' or 'ash' will match 'Bash' tag.

# Exact tag matching:

ftagmark(){ jq -r --arg t "$1" '.children[] as $i|if $i.root == "tagsFolder" then ([$i.children[] as $j|{title: ($j.title), urls: [$j.children[].uri]}]) else empty end|.[] as $k|if $k.title == $t then $k.urls else empty end|.[]?' "$2"; }

Usage: ftagmark TAG BOOKMARKS.JSON

# List all tags:

ftagmarkl(){ jq -r '.children[] as $i | if $i.root == "tagsFolder" then $i.children[].title else empty end' "$1"; }

Usage: ftagmarkl BOOKMARKS.JSON

# Requires: `jq` - must have CLI JSON processor


pv -tpreb /dev/sdc2 | dd of=/dev/sdb2 bs=64K conv=noerror,sync
2016-12-22 03:18:09
User: 4fthawaiian
Functions: dd

uses the wonderful 'pv' command to give a progress bar when copying one partition to another. Amazing for long running dd commands

sed 's/^\([^>.]\)/#\1/;s/^>>> //;s/^\.\.\./ /'
2016-12-06 15:23:02
User: miniker84
Functions: sed

Used to copy and paste a terminal buffer of a python interactive session into an editor

zgrep 'pattern' /var/logs/apache2/access.log* | awk '{print $7}' | sort -n | uniq -c | sort -rn
ls -lart|lolcat -a
2016-11-18 02:45:39
User: knoppix5
Functions: ls

(example above is the 'ls' command with reduced output speed)

cat matching_files.txt | xargs sed -i '' "s/require('global-module')/require('..\/some-folder\/relative-module')/"
whatinstalled() { which "$@" | xargs -r readlink -f | xargs -r dpkg -S ;}
whatinstalled () { local cmdpath=$(realpath -eP $(which -a $1 | grep -E "^/" | tail -n 1) 2>/dev/null) && [ -x "$cmdpath" ] && dpkg -S $cmdpath 2>/dev/null | grep -E ": $cmdpath\$" | cut -d ":" -f 1; }
2016-11-08 16:13:10
User: lordtoran
Functions: cut grep tail which

Put this one-line function somewhere in your shell init, re-login and try

whatinstalled <command>

This is an elaborate wrapper around "dpkg -S", with numerous safeguards. Symlinks and command aliases are resolved. If the searched command is not an existing executable file or was installed by some other means than dpkg/apt, nothing is printed to stdout, otherwise the package name.

grep -Hrn "text" .