Commands tagged date (119)

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

    kFiddle · 2009-04-11 22:26:41 7
  • This command displays a clock on your terminal which updates the time every second. Press Ctrl-C to exit. A couple of variants: A little bit bigger text: watch -t -n1 "date +%T|figlet -f big" You can try other figlet fonts, too. Big sideways characters: watch -n 1 -t '/usr/games/banner -w 30 $(date +%M:%S)' This requires a particular version of banner and a 40-line terminal or you can adjust the width ("30" here). Show Sample Output

    watch -t -n1 "date +%T|figlet"
    dennisw · 2009-06-21 01:02:37 11
  • If you have used bash for any scripting, you've used the date command alot. It's perfect for using as a way to create filename's dynamically within aliases,functions, and commands like below.. This is actually an update to my first alias, since a few commenters (below) had good observations on what was wrong with my first command. # creating a date-based ssh-key for ssh-keygen -f ~/.ssh/`date [email protected]$HOSTNAME-%m-%d-%g` -C '[email protected]' # /home/gpl/.ssh/[email protected] # create a tar+gzip backup of the current directory tar -czf $(date +$HOME/.backups/%m-%d-%g-%R-`sed -u 's/\//#/g' <<< $PWD`.tgz) . # tar -czf /home/gpl/.backups/04-22-10-01:13-#home#gpl#.rr#src.tgz . I personally find myself having to reference date --help quite a bit as a result. So this nice alias saves me a lot of time. This is one bdash mofo. Works in sh and bash (posix), but will likely need to be changed for other shells due to the parameter substitution going on.. Just extend the sed command, I prefer sed to pretty much everything anyways.. but it's always preferable to put in the extra effort to go for as much builtin use as you can. Otherwise it's not a top one-liner, it's a lazyboy recliner. Here's the old version: alias dateh='date --help|sed "/^ *%%/,/^ *%Z/!d;s/ \+/ /g"|while read l;do date "+ %${l/% */}_${l/% */}_${l#* }";done|column -s_ -t' This trick from my [ bash_profile ] Show Sample Output

    alias dateh='date --help|sed -n "/^ *%%/,/^ *%Z/p"|while read l;do F=${l/% */}; date +%$F:"|'"'"'${F//%n/ }'"'"'|${l#* }";done|sed "s/\ *|\ */|/g" |column -s "|" -t'
    AskApache · 2010-04-21 01:22:18 5
  • Not perl but shorter.

    date +%V
    putnamhill · 2009-12-01 21:40:56 1
  • 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 : 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 : Show Sample Output

    xvkbd -xsendevent -text $(date +%Y%m%d)
    sputnick · 2009-12-23 12:01:07 4
  • Not a discovery but a useful one nontheless. In the above example date format is 'yyyymmdd'. For other possible formats see 'man date'. This command can be also very convenient when aliased to some meaningful name: alias mkdd='mkdir $(date +%Y%m%d)'

    mkdir $(date +%Y%m%d)
    thebodzio · 2009-04-25 14:16:45 4
  • Countdown clock - Counts down from $MIN minutes to zero. I let the date command do the maths. This version doesn't use seq. Show Sample Output

    MIN=10;for ((i=MIN*60;i>=0;i--));do echo -ne "\r$(date -d"0+$i sec" +%H:%M:%S)";sleep 1;done
    flatcap · 2011-02-20 11:56:28 7
  • The British Government entering in the Gregorian era. Show Sample Output

    cal 09 1752
    flux · 2009-04-22 00:13:19 4
  • Use `zless` to read the content of your *rss.gz file: zless commandlinefu-contribs-backup-2009-08-10-07.40.39.rss.gz Show Sample Output

    curl<your username>/rss|gzip ->commandlinefu-contribs-backup-$(date +%Y-%m-%d-%H.%M.%S).rss.gz
    linuxrawkstar · 2009-08-10 12:43:33 0
  • Will edit *.db files in the same directory with todays date. Useful for doing a mass update to domains on a nameserver, adding spf records, etc. Looks for a string starting with 200 or 201 followed by 7 numbers, and replaces with todays date. This won't overwrite Ip's but i would still do some double checking after running this. Make sure your server's date is correct, otherwise insert your own serial number. rndc reload should usually follow this command.

    sed -i 's/20[0-1][0-9]\{7\}/'`date +%Y%m%d%I`'/g' *.db
    alf · 2010-03-24 07:28:58 3
  • Uses date to grep de logfile for today and uses it to get the last hour logs. Can be used to get last minute logs or today's logs. Show Sample Output

    grep -i "$(date +%b\ %d\ %H)" syslog
    rubenmoran · 2010-05-23 16:18:15 4
  • This is useful when watching a log file that does not contain timestamps itself. If the file already has content when starting the command, the first lines will have the "wrong" timestamp when the command was started and not when the lines were originally written.

    tail -f file | while read line; do echo -n $(date -u -Ins); echo -e "\t$line"; done
    hfs · 2010-11-19 10:01:57 5
  • date -ud @1320198157

    TZ=UTC date -d @1320198157
    kev · 2011-11-02 01:48:49 0
  • You will see it on the corner of your running terminal. Show Sample Output

    while sleep 1; do tput sc; tput cup 0 $(($(tput cols)-29)); date; tput rc; done &
    rakibfiha · 2019-10-19 20:50:48 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 Show Sample Output

    backup() { for i in "[email protected]"; do cp -va $i $i.$(date +%Y%m%d-%H%M%S); done }
    polaco · 2009-11-10 20:59:45 2
  • Shows a simple clock in the console -t param removes the watch header Ctrl-c to exit Show Sample Output

    watch -t -n1 'date "+%r %F %A"'
    oracular · 2011-02-16 03:05:48 2
  • I removed the dependency of the English language Show Sample Output

    for y in $(seq 1996 2018); do echo -n "$y -> "; for m in $(seq 1 12); do NDATE=$(date --date "$y-$m-13" +%w); if [ $NDATE -eq 5 ]; then PRINTME=$(date --date "$y-$m-13" +%B);echo -n "$PRINTME "; fi; done; echo; done
    ginochen · 2018-06-25 09:20:57 1
  • More recent versions of the date command finally have the ability to decode the unix epoch time into a human readable date. This function makes it simple to utilize this feature quickly. Show Sample Output

    utime { date -d @$1; }
    deltaray · 2010-05-12 12:21:15 0
  • This command prints the Date (Not time) from 3 days ago (72 hours ago). This works on systems without GNU date (MacOSX , Solaris, FreeBSD). Show Sample Output

    TZ=PST8PDT+72 date '+%Y_%m_%d'
    StefanLasiewski · 2010-07-02 00:29:27 6
  • Should be a bit more portable since echo -e/n and date's -Ins are not. Show Sample Output

    tail -f file | while read line; do printf "$(date -u '+%F %T%z')\t$line\n"; done
    derekschrock · 2010-11-24 05:50:12 0
  • Like 7171, but fixed typo, uses fewer variables, and even more cryptic! Show Sample Output

    read -a A<<<".*.**..*....*** 8 9 5 10 6 0 2 11 7 4";for C in `date +"%H%M"|fold -w1`;do echo "${A:${A[C+1]}:4}";done
    __ · 2010-12-02 22:04:49 1

  • 4
    date -s "$(curl -sD - | grep '^Date:' | cut -d' ' -f3-6)Z"
    casueps · 2019-12-20 10:10:14 3

  • 3
    ruby -rdate -e 'p'
    Tekhne · 2009-12-02 02:33:51 1
  • Create a file with actual date as filename Show Sample Output

    touch file-$(date +%Y%m%d)
    rubenmoran · 2010-05-24 07:43:45 2
  • displays current time in "binary clock" format (loosely) inspired by: "Decoding": 8421 .... - 1st hour digit: 0 *..* - 2nd hour digit: 9 (8+1) .*.. - 1st minutes digit: 4 *..* - 2nd minutes digit: 9 (8+1) Prompt-command version: PROMPT_COMMAND='echo "10 i 2 o $(date +"%H%M"|cut -b 1,2,3,4 --output-delimiter=" ") f"|dc|tac|xargs printf "%04d\n"|tr "01" ".*"' Show Sample Output

    echo "10 i 2 o $(date +"%H%M"|cut -b 1,2,3,4 --output-delimiter=' ') f"|dc|tac|xargs printf "%04d\n"|tr "01" ".*"
    unefunge · 2010-11-24 23:49:21 2
  •  1 2 3 >  Last ›

What's this? is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands

Check These Out

generate iso rss parser
you can just use one awk script to parse the rss feed. No need to pipe so many awk's and sed's. Its ugly and inefficient.

Update program providing java on Debian
Lets you set all the java alternatives at once to a matching version. Also has options for just changing the jre or the plugin.

Rename files in batch

nmap port scanning
TCP Connect scanning for localhost and network

Quick and dirty RSS
runs an rss feed through sed replacing the closing tags with newlines and the opening tags with white space making it readable.

Convert a string to "Title Case"
Converts the first letter of each word to upper case

Prefix command output with duration for each line
Prefixes each output line with time between it and the previous one.

Get your IP addresses
Shows the interface and the ip-address

easily find megabyte eating files or directories

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.


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: