Unix/Linux tutorials for beginners

Reader Interactions


  1. Its interesting to see how the start and finish times in your script are identical. I could reproduce the same effect in my shell.

    however, the following code actually incrementy the unixtime in seconds:

    while (sleep 3; sleep 2)
    date +%s

    whereas your code doesnt. I find that strange.

    Has anybody got an explanation for this behavior of bash?


  2. Oops.

    Thats no bash bug at all.

    Its a typo in line 12:
    12 echo "Script finish time (Unix epoch): $START"
    should be
    12 echo "Script finish time (Unix epoch): $FINISH"


  3. Good catch, thanks so much for pointing this out so quickly! Just fixed the original post, hope it won't confuse anyone else…

    I think the reason I didn't notice it was because the elapsed time was calculated correctly to be 5 seconds, so I didn't even question the rest of the output 🙂


  4. Thanks for the comment, Eugene!

    Yes, I was thinking of this form and find it easier to read as well, however I left it out because I haven't explained this bash expression evaluation syntax on my pages yet.

    Will do so this week!

  5. am running process in a Unix box but need to know the time it will take to finish.
    can you help??

  6. Hi James,

    There's no easy way to confirm how long an already running process will take to complete, but I've just posted a quick entry about the time command.

    You can use it to run a command and it will then time exactly how long it took to complete the execution.

    If this isn't what you're looking for, please explain your situation and I'll see what else can be done.

    Thanks for stopping by and good luck!

  7. Hi Dave,

    time command is a great tool when you need to measure the time for running a command or a whole script, your example is perfect.

    But what I'm explaining in this post is timing parts of the script, i.e. a certain execution path within the same script – and last time I checked you couldn't use time command as such a stopwatch.

    Thanks for stopping by! I'll update the post to make it include your example and explain my point a bit better.

  8. Hi Abbadi, glad you liked the article! I post new links more or less every Tuesday, so if I come across such a site I'll definitely share it with everyone. I plan to cover a lot of basics myself, so feel free to submit your questions/topics.

  9. how the date and time automatically reset every 24 hours ? or 12 hours. In macosx


  10. $ date +%s

    it is printing the same %s ….?
    can you pls let me know,y it was printing this.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please join my Unix Tutorial group on Facebook to ask a question or share your Unix experience!
%d bloggers like this: