Manage Time in Ubuntu Through Command Line

What if you would like to manage your computer’s time in Ubuntu? It’s easy if you are in a graphical desktop environment. But what if you are on the command line? For example, in Ubuntu Server? Well, it is easy as well. A very helpful, everything-in-one-place resource is Ubuntu Time.

View Time

To view the current date and time, the following command will be enough

date

Set Time

To change time means to set a new time. To set time in Ubuntu (or any Linux), just run the following command

sudo date newdatetimestring

where newdatetimestring has to follow the format nnddhhmmyyyy.ss which is described below

  • nn is a two digit month, between 01 to 12
  • dd is a two digit day, between 01 and 31, with the regular rules for days according to month and year applying
  • hh is two digit hour, using the 24-hour period so it is between 00 and 23
  • mm is two digit minute, between 00 and 59
  • yyyy is the year; it can be two digit or four digit: your choice. I prefer to use four digit years whenever I can for better clarity and less confusion
  • ss is two digit seconds. Notice the period ‘.’ before the ss.

Let’s say you want to set your computer’s new time to December 6, 2007, 22:43:55, then you would use:

sudo date 120622432007.55

It couldn’t be any easier, could it? The source of this information was a good post on Ubuntu Forums (Set time/date via command line).

Change Time Zone

You may update or change your time zone by

tzconfig
dpkg-reconfigure tzdata (thanks to Mario, see comment below)

This command will guide you through the process of setting a new time zone. You may also choose UTC (GMT) if you want.

If your system does not have tzconfig, you may use something else.

tzselect

If your system does not have tzdata, install it as below:

sudo aptitude install tzdata

This will provide a set of different time zones to choose. If you would like to set the time to UTC, choose the option which says something like ‘none of the above’, or ‘none of these’ or something to this effect. In my case it was option 11. Then it asks for difference from UTC (GMT and GST is also the same thing). I chose GST-0 as the option and it set the time as UTC.

Sync Clock Via NTP

If you want to sync your clock with NTP servers, it is also very easy. Just make sure you have the file ntp.conf file in /etc. How can you check it?

ls /etc/ntp.conf

If you see /etc/ntp.conf as a result, you already have that file. If the ls command gives an error, you do not have it. If so, you may create it yourself.

sudo vim /etc/ntp.conf

This file will be used to automatic synchronization of the clock. I do not know if the client uses this file automatically or one has to configure something first. Thanks to Sean (see comment below): You need to install ntpd in order to make use of this ntp.conf file.

Whether you have the file already or not, make sure it has at least the following data

driftfile /var/lib/ntp/ntp.drift
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server pool.ntp.org

Here you may replace, add, and/or remove any servers you wish. You will find a list of time servers from the public NTP time server list.

You may manually sync the clock using the following

sudo ntpdate servername

where servername can be any public or private time server. You may always choose the following without hesitation

sudo ntpdate pool.ntp.org

If you don’t have ntpdate installed, you can install it via:

sudo aptitude install ntpdate

See, it was quite easy. Enabling NTP Services helped me gain this knowledge.

About these ads

42 Responses to Manage Time in Ubuntu Through Command Line

  1. Pingback: Ни подскажите, который сейчас час? « Wild’s Weblog. Linux

  2. Pingback: Ни подскажите, который сейчас час? « Wild’s Weblog. Linux

  3. Dan says:

    Thanks, now my VMServer is always on time!

  4. Matt says:

    Perfect! Just what I needed!

  5. Pingback: [GLL] blogis » Blog Archive » Ubuntu laiko juosto nustatymas iš konadinės eilutės

  6. Gavin Holt says:

    Thanks very much!

  7. rrees says:

    Thank you, very helpful

  8. Aaron 'Я' God says:

    Thank you. I was wondering how to solve my time problem when it was disabled with my server.

  9. Mario says:

    Thanks. You should note:

    WARNING: the tzconfig command is deprecated, please use: dpkg-reconfigure tzdata

  10. Mohi says:

    Thanks a lot!…i started to hate kubuntu when i failed to change something as simple as the time:P…well…this helped me solve the problem..thnx agen:D

  11. lava says:

    Could I know what command how to change the name in my user settings (not the username but its the name display for the user (realname))

  12. lava says:

    Could I know
    the command to use to change the name in my user settings (not the username but its the name display for the user (realname))

    in UBUNTU

  13. Petunia Bele says:

    Thank you very much that was very help full.

  14. Joe says:

    Thanks for your help. Worked for me yayy :)

  15. FLAVA says:

    GREAT! IT WORKS!!!THANKS A BUNCH

  16. qweeak says:

    tzconfig
    WARNING: the tzconfig command is deprecated, please use:
    dpkg-reconfigure tzdata

    what does this mean ??

  17. sendray says:

    Perfect.. thanks a lot

  18. Pingback: Manage Time in Ubuntu Through Command Line - CS & IT Solutions

  19. Amin Musa says:

    Thank you,

    I’m newbie on UBUNTU

  20. Robert says:

    @qweeak: Well… it means… use “dpkg-reconfigure tzdata” instead. Did you try it ?

  21. Sean says:

    You said:
    “This file will be used to automatic synchronization of the clock. I do not know if the client uses this file automatically or one has to configure something first.”

    You need to install ntpd in order to make use of this ntp.conf file.

    http://doc.ubuntu.com/ubuntu/serverguide/C/NTP.html

  22. vajorie says:

    just wanted to drop a thanks for this :)

  23. Pingback: Manage Time Through Command Line in ubuntu | TurboLinux Blog

  24. Pingback: Migrating from BIND DNS servers to Amazon Route 53 by using cli53 | Open Source Hacker

  25. Anonymous says:

    tank you so much :)

  26. Pingback: Confluence: Projects

  27. Thank you very much…:)

  28. how would I use these commands to show the weekday and day of the month in the Clock please?

    I am unable to do it using the standard dialog in Ubuntu 11.10

  29. Adolphe says:

    Merci beaucoup de voir votre (dpkg-reconfigure tzdata) commande fonctionner!
    It gives desire to progress in Linux in fact!

  30. Anonymous says:

    thank you so much

  31. Pingback: Confluence: Yonder SysAdmin

  32. Aj Banda says:

    thanks for this.. this helped me in my time problem :)

  33. Pingback: LinuxCommands datetime | Geeks' Code Journal

  34. Pingback: Linux datetime | Geeks' Code Journal

  35. CraigInCO says:

    Thank you so much! Noe my mail server has the correct time stamp!

  36. Thnx……i was fighting with time issue….i got the best solution.

  37. dialNforNinja says:

    That does not work, at least not with Precise as installed by crouton for a chromebook. ALl it does is return “date: invalid date mmdhhmmyyyy.ss” with the letters replaced by the numbers that were actually entered.

  38. dialNforNinja says:

    Further attempts to affect anything at all reveals that the txconfig command is not recognized either. Since it thinks it’s on the west coast and I’m 3000 miles east near Boston, that is a good chunk of the problem right there.

  39. Pingback: How do you change the system date by fixed amount of time? | Ubuntu InfoUbuntu Info

  40. Pingback: Windows 8 (8.1) e problema ora! - Pagina 2

  41. blazejkapala says:

    Reblogged this on kapala.com.pl.

  42. Pingback: How to change the timezone in Ubuntu server | HolaRails

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 31 other followers

%d bloggers like this: