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 - 149 results
date -s "$(echo -e "HEAD / HTTP/1.0\n" | nc www.example.com 80 | sed -ne 's/^Date: \(.*\)$/\1/p')"
2010-01-08 20:05:00
User: tomhol
Functions: date
Tags: date
0

Good when firewalled and only in need of a reasonable accurate time.

Use a fast responding web server.

xvkbd -xsendevent -text $(date +%Y%m%d)
2009-12-23 12:01:07
User: sputnick
Functions: date
13

That works in all softs, CLI or GUI... I don't want to waste time to all the time typing the same stuff . So, I have that command in my window manager shortcuts ( meta+l ). All the window managers have editable shortcuts AFAIK. If not, or you don't want to use it that way, you can easily use the xbindkeys soft.

I you're using kde4, you can run :

systemsettings

then open "inputs actions" and create a new shortcut.

For Gnome take a look there : http://www.cyberciti.biz/faq/howto-create-keyboard-shortcuts-in-gnome/

A more advanced one, with strings and newlines :

xvkbd -xsendevent -text "---8<-----\nToday date is: $(date +%Y%m%d)\n---8<-----"

For complicated or long paste, you can feed xvkbd with a file :

xvkbd -xsendevent -file <file>

You can simulate ^C ( control+c ) too or others combinations of keys :

xvkbd -text "\C\Ac"

There's no man page nor help ( On my Archlinux distro ), but you can see online doc there : http://homepage3.nifty.com/tsato/xvkbd/

date +%V
backup() { for i in "$@"; do cp -va $i $i.$(date +%Y%m%d-%H%M%S); done }
2009-11-10 20:59:45
User: polaco
Functions: cp date
Tags: backup copy date
4

This script creates date based backups of the files. It copies the files to the same place the original ones are but with an additional extension that is the timestamp of the copy on the following format: YearMonthDay-HourMinuteSecond

export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | toilet -f shadow'
2009-10-23 07:56:30
User: m33600
Functions: date echo export printf watch
0

already described on the other two versions, this one uses ascii characters on game style to display elapsed time.

export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | osd_cat -o 20 -d 1 -p bottom'
2009-10-23 07:47:11
User: m33600
Functions: date echo export printf watch
0

Variation of the theme, this one blinks in low profile on top level of X, ie, it is visible, indeed small.

Try changing fonts and sizes of osd_cat

export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds)'
2009-10-23 07:31:44
User: m33600
Functions: date echo export printf watch
3

Works on real time clock, unix time based, decrementing the actual time from initial time saved in an environment variable exported to child process inside watch

Shows elapsed time from start of script in hh:mm:ss format

Non afected by system slow down due to the use of date.

for a in bzip2 lzma gzip;do echo -n>$a;for b in $(seq 0 256);do dd if=/dev/zero of=$b.zero bs=$b count=1;c=$(date +%s%N);$a $b.zero;d=$(date +%s%N);total=$(echo $d-$c|bc);echo $total>>$a;rm $b.zero *.bz2 *.lzma *.gz;done;done
2009-10-20 01:00:51
User: matthewbauer
Functions: bzip2 date dd echo seq
3

See: http://imgur.com/JgjK2.png for example.

Do some serious benchmarking from the commandline. This will write to a file with the time it took to compress n bytes to the file (increasing by 1).

Run:

gnuplot -persist <(echo "plot 'lzma' with lines, 'gzip' with lines, 'bzip2' with lines")

To see it in graph form.

date -ud "1970-01-01 + 1234567890 seconds"
2009-10-07 04:35:40
User: zude
Functions: date
6

The "-d" option for gnu's "date" command can calculate positive or negative offset from any time, including "now". You can even specify a source timezone (the output timezone can be set with the TZ environment variable). Useful! Fun! Not very well documented!

date|osd_cat
2009-10-02 18:26:46
User: din7
Functions: date
7

This is very useful if you need to show someone some text from a distance. (Like someone standing over your shoulder...)

I'd recommend aliasing it to something like:

alias osd_cat="osd_cat -o 400 -s 8 -c blue -d 60 -f -*-bitstream\ vera\ sans-*-*-*--200-*-*-*-*-*-*-*"

xosd is the utility that provides osd_cat.

xmms2 mlib search added \> $(echo $(date +%s) - 604800|bc)
echo $(date +%s) > start-time; URL=http://www.google.com; while true; do echo $(curl -L --w %{speed_download} -o/dev/null -s $URL) >> bps; sleep 10; done &
2009-09-19 21:26:06
User: matthewbauer
Functions: date echo sleep
9

This will log your internet download speed.

You can run

gnuplot -persist <(echo "plot 'bps' with lines")

to get a graph of it.

date -ud @$[2**31-1]
2009-09-11 08:48:50
User: Escher
Functions: date
-149

The end of unix time and the 32bit era will be Tue Jan 19 03:14:07 UTC 2038

.

date -ud @$[2**31]

date: invalid date `@2147483648'

.

In 64bit you have much longer, at least to:

date -ud @$[2**55] Sun Jun 13 06:26:08 UTC 1141709097
tar --create --file /path/$HOSTNAME-my_name_file-$(date -I).tar.gz --atime-preserve -p -P --same-owner -z /path/
2009-09-07 04:52:12
User: Odin_sv
Functions: date tar
Tags: backup tar
1

Use tar command for a backup info with a date of creation

date -d @1234567890
date -j -v +1000000000S -f %m%d%Y mmddYYYY
date -j -v +1000000000S -f %m%d%Y mmddyyyy
date -d12/31/1970+1000000000sec
curl http://www.commandlinefu.com/commands/by/<your username>/rss|gzip ->commandlinefu-contribs-backup-$(date +%Y-%m-%d-%H.%M.%S).rss.gz
2009-08-10 12:43:33
Functions: date gzip
10

Use `zless` to read the content of your *rss.gz file:

zless commandlinefu-contribs-backup-2009-08-10-07.40.39.rss.gz
FECHA=$(date +"%F") FINAL="$FECHA.sql.gz" mysqldump -h localhost -u user --password="pass" --opt jdiaz61_lupajuridica | gzip > /home/jdiaz61/www/backup/$FINAL
2009-08-09 14:51:46
User: juancabo
Functions: date gzip
-2

Tres lineas en un shell script para copiar la base de datos diaramente

let utime=$offsetutc*3600+$(date --utc +%s)+3600; date --utc --date=@${utime}
2009-08-07 23:12:14
User: flokra
Functions: date
0

prints out the time for the timezone specified in $offsetutc. So you have less to think about things like: "I'm in utc+4 and my friend in utc-7, can I call him now or will I wake him?"

Note: $offsetutc should be an integer between -12 and 12.

cp path/filename{,-$(date +%Y-%m-%d)}
2009-08-06 13:50:00
User: vutcovici
Functions: cp date
1

It will create a backup of the filename. The advantage is that if you list the folder the backups will be sorted by date. The command works on any unix in bash.

date --date="$(openssl x509 -in xxxxxx.crt -noout -startdate | cut -d= -f 2)" --iso-8601
2009-07-23 23:24:33
User: rez0r
Functions: date
1

A quick and simple way of outputting the start and end date of a certificate, you can simply use 'openssl x509 -in xxxxxx.crt -noout -enddate' to output the end date (ex. notAfter=Feb 01 11:30:32 2009 GMT) and with the date command you format the output to an ISO format.

For the start date use the switch -startdate and for end date use -enddate.

mysqldump [options] |gzip ->mysqldump-$(date +%Y-%m-%d-%H.%M.%S).gz
2009-06-12 12:42:59
Functions: date gzip
1

Performs a mysqldump and gzip-compresses the output file with a timestamp in the resulting dump file. Inspect the file for integrity or fun with this command afterward, if you desire:

zcat mysqldump-2009-06-12-07.41.01.tgz | less
date -d '1 day ago'; date -d '11 hour ago'; date -d '2 hour ago - 3 minute'; date -d '16 hour'
2009-06-01 10:41:56
User: LrdShaper
Functions: date
5

With this command you can get a previous or future date or time. Where can you use this? How about finding all files modified or created in the last 5 mins?

touch -t `echo $(date -d "5 minute ago" "+%G%m%d%H%M.%S")` me && find . -type f -newer me

List all directories created since last week?

touch -t `echo $(date -d "1 week ago" "+%G%m%d%H%M.%S")` me && find . -type d -cnewer me

I'm sure you can think of more ways to use it. Requires coreutils package.