I want to change the timezone of the system clock from the terminal.

This can be done with


"which opens a gui in terminal"


sudo cp /usr/share/zoneinfo/Europe/London /etc/localtime

"which will set to gmt"

But is there a way to set time zone with just the offset ie.-1 or +5 etc?

I need to do this as I'm writing an application to adjust timeoffset or report logs and the only info I have is the user IP. I can use a webapp to find the location of the IP, but then I need to set offset which would be easy IF I could just get the offset of the location, but if I need to find zone and city it would be a real pain.

If anyone knows the answer to how to set system clock with +/-hour would be great.

  • Please help us to pick up the accepted answer. I think @Mitch's answer is the best askubuntu.com/a/323163/22308 – Nam G VU Oct 10 '14 at 5:27
  • 1
    @NamGVU No, Mitch's is not the best solution, it's a "GUI in a terminal" answer. Even the OP said " this wont work as i need to altr timezone from a program without user input i need a command i can feed into terminal not gui solution", and that's the same objective most would want when looking for a "terminal solution," a script-friendly one. Collin Anderson's is better if you know a city, or Ryan's for plain GMT+-n – Xen2050 Mar 25 '17 at 14:23
  • In ubuntu 18.04, tzselect does not open a gui. It has a terminal-based menu selection. – Tim Richardson Dec 2 '18 at 9:35

To change time zone from terminal, just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

sudo dpkg-reconfigure tzdata

Once open, just follow the screens to change the time zone.

  • 14
    this wont work as i need to altr timezone from a program without user input i need a command i can feed into terminal not gui solution thanks for reply – user2155009 Jul 23 '13 at 11:45
  • 1
    thx!!! this helps, byt i'm already changed manually etc/timezone =) like php.net/manual/en/timezones.php !!! absolutely identical !!! – Vladimir Ch Feb 25 '17 at 17:05
  • Reconfiguring tzdata seems to adjust the hardware clock too so that the displayed time stays the same after the time zone switch. You might want that if your time was correct but time zone was wrong. However you definitely don't want to touch your hardware clock while traveling. The timedatectl approach seems to change time zone only. – SnakE Apr 11 '17 at 9:55
  • @SnakE for me displayed time changes accordingly – RiaD Nov 13 '17 at 8:19
  • i changed it from putty from commad line without any problem why you said that my friend? @ADTC – saber tabatabaee yazdi Dec 4 '17 at 8:46

You can also use the new timedatectl to set the time in 14.04.

sudo timedatectl set-timezone America/New_York
  • How do you install it on ubuntu? – Division by Zero May 25 '15 at 4:09
  • 1
    It's installed by default on 14.04. – Collin Anderson Jun 30 '15 at 19:24
  • 7
    To see all available options, you can run ls -R --group-directories-first /usr/share/zoneinfo. (Be careful not to modify or erase any file here.) More info about posix and right prefixes is here. – ADTC Jan 9 '16 at 5:57
  • 3
    Use sudo timedatectl set-timezone Etc/UTC for UTC. – Zoltán Aug 22 '16 at 14:22
  • 1
    sudo timedatectl list-timezones to show all available timezones. – AlikElzin-kilaka Mar 24 '19 at 16:40

I realize this thread is a bit dated, but I was looking for a better solution because I needed to automatically set the timezone in a VM after a user downloads it from our website and deploys it. Here's what I ended up with:

echo "Setting TimeZone..."
export tz=`wget -qO - http://geoip.ubuntu.com/lookup | sed -n -e 's/.*<TimeZone>\(.*\)<\/TimeZone>.*/\1/p'` &&  timedatectl set-timezone $tz
export tz=`timedatectl status| grep Timezone | awk '{print $2}'`
echo "TimeZone set to $tz"

This will query geoip.ubuntu.com from the server once it is started on the new network (my script checks for connectivity first course) and then set the server's timezone based on the response.

The "wget -q0 -" tells wget to output only the results to stdout which is then piped to the $tz variable.

Hope it helps someone!

  • 1
    Great! On Ubuntu 16.04 it should be "grep zone" and "print $3" instead. – user334639 Dec 20 '16 at 12:56
  • I propose a different cli for getting the timezone. A bit cleaner in my view: curl -s 'geoip.ubuntu.com/lookup' | xmllint --xpath '/Response/TimeZone/text()' - – Darko Miletic Sep 25 '17 at 13:33

You can use the GMT±x files in /usr/share/zoneinfo/Etc.

sudo ln -fs /usr/share/zoneinfo/Etc/GMT$offset /etc/localtime
  • thanks allot for reply im getting an error ln: failed to create symbolic link `/etc/localtime': File exists oboiusly im not sure what im doing do you know of good tutorial for this or even some key words i can google thanks am i using command correctly? im using sudo ln /usr/share/zoneinfo/Etc/GMT$+1 /etc/localtime to set clock to +1gmt – user2155009 Jul 22 '13 at 21:18
  • 9
    minitech forgot the force flag I guess so -> sudo ln -sf .... – Tele Oct 28 '13 at 17:11
  • 1
    This will kinda work, but won't update the tz name in /etc/timezone. – poolie Jul 17 '16 at 14:51
  • 1
    To get the /etc/timezone updated, run sudo dpkg-reconfigure --frontend noninteractive tzdata – Pierre Gramme Mar 12 '19 at 10:52

TL;DR /etc/localtime is a symbolic link that points to a file in /usr/share/zoneinfo/Continent/City. By altering where it points you can alter your timezone.

In order to change timezone, remove the /etc/localtime and assign symbolic link to your desired city. For instance, ls -l /etc/localtime reports that this file points to /usr/share/zoneinfo/America/Denver. To change it to New York, I do

  1. sudo rm /etc/localtime
  2. sudo ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
  3. Wait a minute for my clock to get updated

The screenshot bellow shows the steps and confirmation from timedatectl

enter image description here

  • it's nice to understand what is happening behind the curtain, but don't you think it would be better to suggest the designated tools for this like dpkg-reconfigure tzdata etc.? – Patrick Cornelissen Jan 15 '17 at 9:20
  • @PatrickCornelissen First of all, there's answers for tzdata already, so suggesting same thing is pointless. Second, tzdata does pretty much the same. It's up to user to decide what they prefer, so it's neither better nor worse - just a person's preference. – Sergiy Kolodyazhnyy Jan 15 '17 at 9:39
  • 1
    Well, working "against" the distribution tools often leads to problems, so I'd avoid your approach if possible, but fair enough your solution would work (currently) – Patrick Cornelissen Jan 17 '17 at 8:42
  • This solution as I understand, works across different distributions. But still needs the timezone database available in the /usr/share/zoneinfo directory. Is there a way to get the timezone database without installing tzdata package? – andho May 8 '17 at 7:30
  • @andho Since /var/lib/dpkg/info/tzdata.list suggests that all items in /usr/share/zoneinfo come with that package, I would assume you do need to install the package in order to have all the items, but frankly I'm not quite sure, plus not quite familiar with how this works on other distributions. Consider asking this as a question on Unix & Linux, and feel free to reference this post if you want to provide context for the question. – Sergiy Kolodyazhnyy May 8 '17 at 7:52

The easy way to update the timezone is to use sudo dpkg-reconfigure tzdata. But this isn't so easily scripted.

If you want to set the timezone explicitly via a script (e.g. for setting up a VM), here's a recipe:

Set a variable for the timezone you want, e.g. one of


Valid values are the directories and filenames under /usr/share/zoneinfo.

Then simply

sudo cp -vf /usr/share/zoneinfo/$tz /etc/localtime
echo $tz | sudo tee /etc/timezone

Note that both /etc/localtime and /etc/timezone must be consistent.

Probably now reboot to get all your services updated too (e.g. cron).

  • -1: Do not ever use cp to set /etc/localtime. /etc/localtime is a symlink to the correct file. If you use cp to change it, you will actually clobber the contents of whatever tzdata file it's currently pointing to, so suddenly (for example) the UTC tzdata file contains timezone data for Europe/London instead of for UTC, which is bad (and annoying to troubleshoot, as I can say from personal experience) – Foogod Jul 18 '18 at 7:33

Here's the method I use, which is US-centric as I don't need to worry about non-US time zones.

If I need to determine the current time zone, I either do:

cat /etc/timezone  


sudo hwclock --show  

I then do:

timedatectl set-timezone <_designation_>

where <_designation_> is one of the following:



timedatectl set-timezone US/Eastern  

Other timezone designations can be found here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

  • tzselect is a nice way to get the timezone string – Martin Thoma Nov 14 '18 at 9:15

You cannot do this unless you select the time zone file you want to correspond to each time zone offset.

Some answers suggested using the files in /usr/share/zoneinfo/Etc, but the problem with these is that they are DST agnostic.

So unless you pick some time zone configuration to match each offset, or you don't care about DST, there is no way to do it generically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.