Hide

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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using date from sorted by
Terminal - Commands using date - 146 results
date -r foo
date -d@1234567890
2009-04-11 22:26:41
User: kFiddle
Functions: date
Tags: date
43

This example, for example, produces the output, "Fri Feb 13 15:26:30 EST 2009"

tar -czvvf backup$(date "+%Y%m%d_%H%M%S").tar.gz /path/to/dir
2009-04-10 21:37:17
Functions: date tar
5

creates a tar.gz with a name like:

backup20090410_173053.tar.gz

of a given directory.

this file was made 10 April 2009 at 5:30:53pm

see date's man page to customize the timestamp format

echo $( (( $( (2**31 -1) ) - $(date +%s) )) )
2009-04-02 05:14:23
User: Chartreuse
Functions: date echo
Tags: bash echo date
0

Echos the number of seconds from the current time till the specified time (Example in command is (2**31-1)) aka the Unix epoch. Just replace that number with the specified date (in seconds past Jan. 1st 1970) and it will return the seconds.

NOTE: Only works in bash

date +%m/%d/%y%X|tr -d 'n' >>datemp.log&& sensors|grep +5V|cut -d "(" -f1|tr -d 'n'>> datemp.log && sensors |grep Temp |cut -d "(" -f1|tr -d 'n'>>datemp.log
2009-03-31 18:13:23
User: f241vc15
Functions: cut date grep sensors tr
0
cat datemp.log

04/01/0902:11:42

Sys Temp: +11.0?C

CPU Temp: +35.5?C

AUX Temp: +3.0?C

date -d @$(echo $((2 ** 31 - 1)))
2009-03-30 19:42:20
User: jnash
Functions: date echo
1

http://en.wikipedia.org/wiki/Year_2038_problem

Some other notable dates that have passed:

date -d@1234567890 date -d@1000000000
date -d "@$(find dir -type f -printf '%C@\n' | sort -n | sed -n "$(($(find dir -type f | wc -l)/2))p")" +%F
2009-03-24 18:48:49
User: allengarvin
Functions: date dir find wc
-1

I needed to get a feel for how "old" different websites were, based on their directories.

date --date=yesterday
vi ~/journal/$(date +%F)
2009-03-18 23:31:13
User: ar
Functions: date vi
1

prerequisite:

mkdir ~/journal
date --iso
2009-02-25 23:50:40
User: raphink
Functions: date
-1

Useful to archive files once a day:

cp file file.$(date --iso)
date -d '2 weeks ago Saturday' +%Y-%m-%d
2009-02-21 16:42:52
User: NPH
Functions: date
14

Good for automating reports that need to run from between two dates.

date "+The time is %H:%M" | say
2009-02-20 20:14:53
User: las3rjock
Functions: date
0

On other systems, replace 'say' with the name of another text-to-speech engine, e.g. espeak ( http://espeak.sourceforge.net ) or festival ( http://www.cstr.ed.ac.uk/projects/festival )

date -R -d @1234567890
date +%s
2009-02-13 13:30:44
User: legba7
Functions: date
4

displays time in seconds since January 1, 1970 UTC

tar zcvf somedir-$(date +%Y%m%d-%H%M).tar.gz somedir/
2009-02-10 15:25:40
User: kmac
Functions: date tar
3

A useful bash function:

gztardir()

{

if [ $# -ne 1 ] ; then

echo "incorrect arguments: should be gztardir "

else

tar zcvf "${1%/}-$(date +%Y%m%d-%H%M).tar.gz" "$1"

fi

}

archivefile=filename-$(date +%Y%m%d-%H%M).tar.gz
sudo date mmddhhxxyyyy
sudo date -s "26 OCT 2008 19:30:00"
date -d 09/20/1981 +"%Y-%m-%d"
date --date="1 fortnight ago"
2009-02-06 20:57:59
User: mkc
Functions: date
3

The date command does offset calculations nicely, handles concepts like "a month" as you'd expect, and is good for offsets of at least 100M years in either direction.

date --utc --date "2009-02-06 09:57:54" +%s
2009-02-06 08:29:12
User: michelem
Functions: date
2

Simple way to get a timestamp from a date