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 date from sorted by
Terminal - Commands using date - 171 results
date -u `ssh [email protected] date -u '+%m%d%H%M%Y.%S'`
2014-02-10 03:11:14
User: scruss
Functions: date

Useful if localhost is a small machine running BusyBox, which uses a slightly unusual format to set the date. Remotehost can be pretty much any Linux machine, including one running BusyBox. Uses UTC for portability.

(date "+%d-%m-%Y %H:%M:%S";curl -s --interface lo:1 ifconfig.me| xargs -t geoiplookup 2>&1)|sed -e 's/geoiplookup/IP:/g' -e 's/GeoIP Country Edition/Country/g'|tr -s "\n" " "|sed 'a\ '
2013-10-07 15:28:55
User: guerito
Functions: date sed tr xargs

My first command :) I made this command to log public addresses of a virtual interface who connects random VPN servers around the world.

alias timer='export ts=$(date +%s);p='\''$(date -u -d @"$(($(date +%s)-$ts))" +"%H.%M.%S")'\'';watch -n 1 -t banner $p;eval "echo $p"'
2013-08-24 16:18:45
User: ichbins
Functions: alias banner date eval watch
Tags: timer banner

Starts and shows a timer. banner command is a part of the sysvbanner package. Instead of the banner an echo or figlet commands could be used. Stop the timer with Ctrl-C and elapsed time will be shown as the result.

curl -sL http://www.dell.com/support/troubleshooting/us/en/555/Servicetag/$(dmidecode -s system-serial-number) | html2text -style pretty | awk -F\. '/with an end date of/ { print $1 "."}'
2013-07-30 14:46:12
User: mhollick
Functions: awk date

pretty much the same.

I use awk rather than grep and perl.

It looks like the URL has been updated.

The service tag can also be retrieved via snmp - potential for a for loop over a list of servers. I might have a look into doing an example.

date --set="$(ssh [email protected] 'date -u')"
2013-06-03 06:43:49
Functions: date
Tags: ssh ,NTP ,Date

using -u is better for standardizing date output and timezones, for servers in different timezones.

date -d @1234567890
date '+%y%m%d-%H%M%S'
while (true); do date --utc; done | uniq -c
-y -r 1 -t 3 -f video4linux2 -vframes 1 -s sxga -i /dev/video0 ~/webcam-$(date +%m_%d_%Y_%H_%M).jpeg
2013-02-27 05:32:03
User: navyjeff
Functions: date

Take a picture from your webcam and save it to a jpeg.

A very slightly modified version of MarxBro's command.

while true; do (date | tr "\n" ";") && ping -q -c 1 www.google.com|tail -1|cut -d/ -f5 ;sleep 1; done >> uptime.csv
2013-02-06 22:06:09
User: fanchok
Functions: cut date ping sleep tail tr

Used in OS X.

tr "\n" ";"

may be replaced by

echo ";"

with linux versions of date.

I reused

ping -q -c 1 www.google.com|tail -1|cut -d/ -f5

read && ffmpeg -y -r 1 -t 3 -f video4linux2 -vframes 1 -s sxga -i /dev/video0 ~/webcam-$(date +%m_%d_%Y_%H_%M).jpeg
2013-01-17 11:37:09
User: MarxBro
Functions: date read

This command takes a 1280x1024 p picture from the webcam.

If prefer it smaller, try changing the -s parameter: qqvga is the tiniest, vga is 640x480, svga is 800x600 and so on.

Get your smile on and press enter! :)

while(true); do printf "%s\f" $(date +%T); sleep 1; done | sm -
2013-01-14 17:13:34
User: claudius
Functions: date printf sleep
Tags: time clock sm

http://www.joachim-breitner.de/projects#screen-message now also supports reading stdin continuously to update what it shows, different ?slides? separated by a form feed character. Here, we feed the current time into it each second to create a large clock.

gzip -c ~/.bash_history > ~/.backup/history-save-$(date +\%d-\%m-\%y-\%T).gz
2013-01-11 17:31:07
User: tictacbum
Functions: date gzip
Tags: history backup

this one works on user crontab

if date -d 2006-10-10 >> /dev/null 2>&1; then echo 1; else echo 0; fi
2013-01-10 10:35:15
Functions: date echo

On CentOS at least, date returns a boolean for the common date string formats, including YYYY-MM-DD. In the sample output, you can see various invalid dates returning 0 whereas a simple regex check would return 1 for the invalid dates.

-d, --date=STRING display time described by STRING, not `now'

The version of date on OS X does not appear to have this same option.

sleep $((3600 - ($(date +%s) % 3600) ))
2012-12-09 16:21:57
User: Mozai
Functions: date sleep

pauses exactly long enough to wake at the top of the hour

date +%:z
ngrep host -O $(date +%Y%m%d_%H%M%S).pcap > $(date +%Y%m%d_%H%M%S).txt
history > ~/history-save-$(date +%d-%m-%y-%T)
2012-08-18 07:40:33
Functions: date
Tags: history

simple and easy backup your history with timestamp

seq 1 5 | xargs -I"#" date --date="today -# days" +'%Y-%m-%d'
desiredDay=6; year=2012; month=5; n=0; while [ $(date -d "$year-$((month+1))-1 - $n day" "+%u") -ne $desiredDay ]; do n=$((n+1)); done; date -d "$year-$((month+1))-1 - $n day" "+%x"
2012-05-17 12:02:30
Functions: date

Choosing your year and month. You only need the gnu date command and bash. desiredDay of the week is (1..7); 1 is Monday.

If you want desiredDay of week (0..6); 0 is Sunday

desiredDay=6; year=2012; month=5; n=0; while [ $(date -d "$year-$((month+1))-1 - $n day" "+%w") -ne $desiredDay ]; do n=$((n+1)); done; date -d "$year-$((month+1))-1 - $n day" "+%x"
svnlook date /path/to/repo
2012-04-03 16:29:00
User: ijeyanthan
Functions: date

command to find out the unused SVN repositories from the server via svnlook. This lists the when the last commit (HEAD revision) has happened in the repository.

date +%s
2012-03-12 00:14:22
User: akhilravidas
Functions: date
Tags: date epoch

Get the time since epoch. Useful when working with commands and logs which use this format.

step1() { k1="Consumer key" ; k2="Consumer secret" ; k3="Access token" ; k4="Access token secret" ; once=$RANDOM ; ts=$(date +%s) ; hmac="$k2&$k4" ; id="19258798" ; }
2012-03-11 20:40:56
User: nixnax
Functions: date

Twitter stream feeds now require authentication.

This command is the FIRST in a set of five commands you'll need to get Twitter authorization for your final Twitter command.

*** IMPORTANT *** Before you start, you have to get some authorization info for your "app" from Twitter. Carefully follow the instructions below:

Go to dev.twitter.com/apps and choose "Create a new application". Fill in the form. You can pick any name for your app.

After submitting, click on "Create my access token". Keep the resulting page open, as you'll need information from it below.

If you closed the page, or want to get back to it in the future, just go to dev.twitter.com/apps

Now customize FIVE THINGS on the command line as follows:

1. Replace the string "Consumer key" by copying & pasting your custom consumer key from the Twitter apps page.

2. Replace the string "Consumer secret" by copying & pasting your consumer secret from the Twitter apps page.

3. Replace the string "Access token" by copying & pasting your access token from the Twitter apps page.

4. Replace string "Access token secret" by copying & pasting your own token secret from the Twitter apps page.

5. Replace the string 19258798 with the Twitter UserID NUMBER (this is **NOT** the normal Twitter NAME of the user you want the tweet feed from. If you don't know the UserID number, head over to www.idfromuser.com and type in the user's regular Twitter name. The site will return their Twitter UserID number to you. 19258798 is the Twitter UserID for commandlinefu, so if you don't change that, you'll receive commandlinefu tweets, uhm... on the commandline :)

Congratulations! You're done creating all the keys!

Environment variables k1, k2, k3, and k4 now hold the four Twitter keys you will need for your next step.

The variables should really have been named better, e.g. "Consumer_key", but in later commands the 256-character limit forced me to use short, unclear names here. Just remember k stands for "key".

Again, remember, you can always review your requested Twitter keys at dev.twitter.com/apps.

Our command line also creates four additional environment variables that are needed in the oauth process: "once", "ts", "hmac" and "id". "once" is a random number used only once that is part of the oauth procedure. HMAC is the actual key that will be used later for signing the base string. "ts" is a timestamp in the Posix time format. The last variable (id) is the user id number of the Twitter user you want to get feeds from. Note that id is ***NOT*** the twitter name, if you didn't know that, see www.idfromuser.com

If you want to learn more about oauth authentication, visit oauth.net and/or go to dev.twitter.com/apps, click on any of your apps and then click on "Oauth tool"

Now go look at my next command, i.e. step2, to see what happens next to these eight variables.

date --date="90 days ago"
2012-03-07 07:49:27
User: dan
Functions: date
Tags: date

Gets any date since today. Other examples of recognized expressions are "2 years 4 days ago", "7 months" (in the future), "next Sunday", "yesterday", "tomorrow", etc.