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 tagged time from sorted by
Terminal - Commands tagged time - 31 results
dd bs=1M if=/dev/scd0 of=./filename.iso OR readom -v dev='D:' f='./filename.iso' speed=2 retries=8
2013-10-23 15:53:27
User: scotharkins
Functions: dd
-1

This example is taken from Cygwin running on Win7Ent-64. Device names will vary by platform.

Both commands resulted in identical files per the output of md5sum, and ran in the same time down to the second (2m45s), less than 100ms apart. I timed the commands with 'time', which added before 'dd' or 'readom' gives execution times after the command completes. See 'man time' for more info...it can be found on any Unix or Linux newer than 1973. Yeah, that means everywhere.

readom is supposed to guarantee good reads, and does support flags for bypassing bad blocks where dd will either fail or hang.

readom's verbosity gave more interesting output than dd.

On Cygwin, my attempt with 'readom' from the first answer actually ended up reading my hard drive. Both attempts got to 5GB before I killed them, seeing as that is past any CD or standard DVD.

dd:

'bs=1M' says "read 1MB into RAM from source, then write that 1MB to output. I also tested 10MB, which shaved the time down to 2m42s.

'if=/dev/scd0' selects Cygwin's representation of the first CD-ROM drive.

'of=./filename.iso' simply means "create filename.iso in the current directory."

readom:

'-v' says "be a little noisy (verbose)." The man page implies more verbosity with more 'v's, e.g. -vvv.

dev='D:' in Cygwin explicitly specifies the D-drive. I tried other entries, like '/dev/scd0' and '2,0', but both read from my hard drive instead of the CD-ROM. I imagine my LUN-foo (2,0) was off for my system, but on Cygwin 'D:' sort of "cut to the chase" and did the job.

f='./filename.iso' specifies the output file.

speed=2 simply sets the speed at which the CD is read. I also tried 4, which ran the exact same 2m45s.

retries=8 simply means try reading a block up to 8 times before giving up. This is useful for damaged media (scratches, glue lines, etc.), allowing you to automatically "get everything that can be copied" so you at least have most of the data.

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
1

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.

/usr/bin/time -f "%E real\t%U user\t%S sys" pipeline
ssh remotehosts;date
2012-11-09 01:14:24
User: kiiwii
Functions: ssh
-3

Run this within a steady screen session.

You can get the approximate time when the remote server went down or other abnormal behavior.

date +%:z
cat log | perl -ne 'use POSIX; s/([\d.]+)/strftime "%y-%m-%d %H:%M:%S", localtime $1/e,print if /./'
2012-09-19 06:38:31
User: bs
Functions: cat perl
0

works where perl works, because the awk version is gnu awk only.

echo 00:29:36 | sed s/:/*60+/g | bc
awk 'FNR==100 {print;exit}' file
2012-03-04 20:25:57
User: Testuser_01
Functions: awk
Tags: awk time LINES
0

This will save parsing time for operations on very big files.

date -d '2011-12-15 05:47:09' +"epoch: %s or format: %Y/%m/%d"
date -d @$(echo $(($(date +%s)-$(cat /proc/uptime|cut -d. -f1))))
date -ud "1970/01/01 00:29:36" +%s
2011-11-01 17:02:46
User: frans
Functions: date
Tags: echo date time
-5

uses the -u switch for UTC

Another way could be

echo $(($(date -ud "00:29:36" +%s)%86400))
TZ=GMT date -d "1970/01/01 00:29:36" +%s
echo "notify-send TimeToQuit" | at 10:22
TIME=$( { time redis-cli PING; } 2>&1 ) ; echo $TIME | awk '{print $3}' | sed 's/0m//; s/\.//; s/s//; s/^0.[^[1-9]*//g;'
2011-08-11 19:09:49
User: allrightname
Functions: awk echo sed time
-1

Outputs the real time it takes a Redis ping to run in thousands of a second without any proceeding 0's. Useful for logging or scripted action.

tail -f /var/log/squid/access.loc | ccze -CA
tail -f /var/log/squid/access.log | perl -p -e 's/^([0-9]*)/"[".localtime($1)."]"/e'
curl -Is google.com | grep Date
2011-06-24 11:19:47
User: d3Xt3r
Functions: grep
Tags: http date time
2

This command will show the current GMT time using HTTP. This might be useful if you just want to know what's the current human-readable and accurate-enough time, without changing the system time, using a simple command that would work regardless of the availability of NTP.

Note: To get a quicker and more accurate response, replace google.com with your local NTP server.

Also can be used as an alternative to the "htpdate" program:

http://www.commandlinefu.com/commands/view/668/set-your-computers-clock-using-http-and-htp-http-time-protocol-when-ntpsntp-is-not-available

nawk 'BEGIN {print srand()}'
2011-01-12 16:17:59
User: EBAH
0

For Solaris to obtain the same as:

date+%s like in linux

export PS1="(\@) $PS1"
2010-11-22 04:50:21
User: cmdq
Functions: export
Tags: bash time ps1
1

Adds the time in 12hr AM/PM format to the beginning of a prompt. Change \@ to \t for 24-hour time or \T for 12hr without AM/PM.

To keep the time the next time you open a terminal, edit ~/.bashrc and stick the command at the bottom.

TIME=$( { time YOUR_COMMAND_HERE; } 2>&1 ) ; echo $TIME
2010-11-18 15:48:05
User: allrightname
Functions: echo time
1

I've had a horrible time trying to pipe the output of some shell built-ins like 'time' to other programs. The built-in doesn't output to stdout or stderr most of the time but using the above will let you pipe the output to something else.

sudo find . -maxdepth 1 -cnewer olderFilesNameToMove -and ! -cnewer newerFileNameToMove -exec mv -v {} /newDirectory/ \;
2010-06-30 20:40:30
User: javamaniac
Functions: find mv sudo
2

In a folder with many files and folders, you want to move all files where the date is >= the file olderFilesNameToMove and

watch -tn1 'date -u +%T -d @$(expr $(date -d HH:MM +%s) - $(date +%s)) | toilet -f bigmono12'
2010-06-26 11:56:11
User: prayer
Functions: date expr watch
Tags: date time
-2

Change HH:MM with your target time.

This is for a Debian/Ubuntu GNU system. You need bash (package bash), date (package coreutils) and toilet (package toilet). Install with:

# apt-get install bash coreutils toilet toilet-fonts

utime(){ python -c "import time; print(time.strftime('%a %b %d %H:%M:%S %Y', time.localtime($1)))"; }
utime(){ awk -v d=$1 'BEGIN{print strftime("%a %b %d %H:%M:%S %Y", d)}'; }
utime(){ date -d "1970-01-01 GMT $1 seconds"; }