How to change computer's time using Fluxbox (Linux)
March 8, 2009 10:18 AM   Subscribe

My computer has Fluxbox installed on it. How do I update the time on my computer?

It went from 25 minutes fast to 35 minutes slow, and it's driving me crazy! I don't know what to ask Google to get a useful answer.

Thanks!
posted by aniola to Computers & Internet (18 answers total)
 
Use the 'date' command in a console:

date 03081321
posted by sonic meat machine at 10:21 AM on March 8, 2009


After running date, run:

sudo /sbin/hwclock --systohc

This will set the hardware clock to the system time, thus syncing the two (unless your hardware clock is UTC. If so, sudo /sbin/hwclock --systohc --utc will set it correctly)
posted by Cat Pie Hurts at 10:36 AM on March 8, 2009 [1 favorite]


Best answer: aniola: I don't know what to ask Google to get a useful answer.

Don't google! Here, I'll show you - this is easy, and if you're running Linux, you should know:

1) Open up a command terminal, sometimes also called a 'console.'

2) Now, what you want to find is a command that lets you change the time. In Linux, if you want to find a command that does something, you just type apropos and then the thing you want to do. In this case, you type

apropos time

and press enter, and you'll get a list of commands that have to do with time.

3) In Linux, there are handy manual pages (often called 'man pages') for all of the commands so that you can learn what they are and what they do. You can look at these by typing man before the command and pressing enter. So go through the different commands that have to do with time and look at their man pages. (When you're done looking at a man page, you can close it by pressing q.)

4) After a little looking, you should notice that it's the date command that you wanted.

You can go through this process any time you want to do anything in Linux. Sometimes you might have to google a little, too, but the nice thing about this is it's always there for you (even when you don't have the internet) and it's often faster than google. In this case, I know that date formatting can be strange. You can look at this reference page on O'Reilly's web site to learn a little more about how that will work. (The book it's taken from, "Linux In A Nutshell," is great, by the way; it's like a compendium of expanded man pages, so it can be very useful.) Basically, it goes like this.

date

just as a command will tell you the current date/time settings (in a pretty coherent way.) So to change the time, press:

date -s 0308134509

...meaning: set (-s) the date/time (date) to March (03) 8th (08), 1:45 pm (1345), 2009 (09). So that the format is:

date -s mmddttttyy

Hope this helps. (Sorry if you already knew a bunch of this - I just figure that the command line is worth knowing a bit about.)
posted by koeselitz at 10:51 AM on March 8, 2009 [3 favorites]


Response by poster: Koeselitz - Thanks! That was a treasure trove of cool information that I'd been trying to pry out of my linux-using friends for months.

I'm still having some trouble navigating this labyrinth of new language. don't know how to make use of all that information that I now know how to access....

When I try doing date 0308114209 (or date 03081142) it tells me "date: cannot set date: operation not permitted" and when I try doing date -s 0308114509 it tells me "date: invalid date '0308114509'"
posted by aniola at 11:47 AM on March 8, 2009 [1 favorite]


It went from 25 minutes fast to 35 minutes slow, and it's driving me crazy!
If you're in the US, and if you compared your computer's time to standard time yesterday, and to daylight-savings time today, then what you describe seeing would fit perfectly. (Not dismissing the rest of your post - you do need to set the clock).
posted by TruncatedTiller at 11:51 AM on March 8, 2009


Best answer: What linux distro are you running? I can't think of any that use Fluxbox by default.

You'll want to preface the command with 'sudo' (superuser do). this effectively executes a command as root without the inherent dangers of running as root:

sudo date 0308114209

You should be prompted for your password.

If the password fails, then your user account isn't in the sudoers. Add it this way:

type:
su - root
(enter root password)

visudo
(this will bring up a text editor - either vi or nano depending on your distro)

add the following line:

yourUsername ALL=(ALL) ALL
(Some people may yell at me about the above as this grants full sudo access to everything and everything.)
save, quit and run sudo date again.
posted by Cat Pie Hurts at 11:58 AM on March 8, 2009 [1 favorite]


Response by poster: TruncatedTiller. I'm aware of Daylight Savings. I'm just frustrated 'cause I don't know how to make my computer reflect that. It seems like it should be so simple....
posted by aniola at 11:58 AM on March 8, 2009


Response by poster: WOOT! Thanks, y'all! Time's working!
posted by aniola at 12:00 PM on March 8, 2009


Awesome. Happy to help.

One of the coolest things about Linux is that, if you know apropos and man, you can learn it all yourself and find almost anything you'll ever need.
posted by koeselitz at 12:08 PM on March 8, 2009


You might want to check and see that a ntp daemon is installed (and running) on your system, or at least ntpdate. They check the time with Network Time Protocol servers, and set your computer's clock to their time (all done in UTC, so DST is taken care of).
posted by philomathoholic at 12:15 PM on March 8, 2009


Some people may yell at me about the above as this grants full sudo access to everything and everything.

Looks like the OP has already got an answer, so I'll go ahead and ask: How is allowing sudo for everything safer than logging in as root for a couple of commands? In fact, in a multiuser machine (apparently not the case) this looks like a pretty dumb thing to do.

I would also like to nominate koselitz for this year's Golden Penguin.
posted by ghost of a past number at 12:15 PM on March 8, 2009


ghost of a past number: for me, the need to "sudo" every time reminds me that I'm about to do something dangerous. And you can't leave yourself logged in as root absent-mindedly.

I don't buy the idea that sudo for everything is any more secure than logging in as root, but it works for me as a usability thing.
posted by i_am_joe's_spleen at 12:29 PM on March 8, 2009


If you want to keep the time updated to a nuclear clock, throw in a cron job running as root once a day that does:

ntpdate pool.ntp.org

If you're using Ubuntu (this likely applies to Debian or other Debian derivatives) just drop into /etc/cron.daily a file called "ntpdate" containing:

#!/bin/sh
/usr/sbin/ntpdate pool.ntp.org

If your computer's not generally left on all the time, install the "anacron" package, which will try to make sure daily jobs are run despite your computer not being on when they were originally scheduled.
posted by Zed at 1:20 PM on March 8, 2009


Response by poster: Zed: Could you walk me through that, step by step?
posted by aniola at 2:28 PM on March 8, 2009


ntpdate us.pool.ntp.org will give slightly better results for your location. The corresponding entry in /etc/ntp.conf for using ntpd would be
	   server 0.north-america.pool.ntp.org
	   server 1.north-america.pool.ntp.org
	   server 2.north-america.pool.ntp.org
	   server 3.north-america.pool.ntp.org

Linux distro's often come with ntpd installed and need a minimum of configuration (i.e. adding the above lines to /etc/ntp.conf). Then you will only need to run ntpdate once and it should take care of itself.
posted by tallus at 4:00 PM on March 8, 2009


Well (jumping in here) I've never done this, and unfortunately I don't have Linux in front of me right now, but I can go over what Zed's proposing.

If your system is always on:

Let's do this with vi - that seems like the easiest way. Vi is a text editor that's existed in Linux and Unix before it since 1976; it was one of the two main contenders during the fabled editor wars. The other, Emacs, is the crazy, complicated, every-feature-imaginable one - people used to joke that Emacs is a great operating system that has everything but a good text editor. Vi, however, was the basic one that was sleeker and more straightforward. They're both very different, and they're both powerful, but Vi is a quick way to create a little file like you want to here. The common version now is Vi Improved, which goes by vim in Linux.

So, at the command line, go:

vim /etc/cron.daily/ntpdate

That will take you into the Vi Improved editor, first creating a file called ntpdate in /etc/cron.daily/. This is a pretty good guide to using Vi if you want to use it later on, but for our purposes, well, what you want to do is pretty simple.

Once you're in the editor, press i to enter insert mode, and type

#!/bin/sh
/usr/sbin/ntpdate pool.ntp.org


[A translation of that: that first line is usually called a 'hash-bang;' it's what tells Linux how to run this program. In this case, the little program you're writing is what's called a shell script, just some commands that you could normally type into the shell (the command line) put together into a script so you don't have to type them out. The second line runs the ntpdate command to connect to the ntp server at pool.ntp.org.]

Once you've typed that out, press Escape to leave insert mode and enter command mode again. Then press : and then w; :q is the command for "save and quit."

You can see why lots of people say that Vi is the fastest editor - all you have to do is vim (filename) [Enter] i (text) [Escape] :q and you've created and saved a file. (I like Emacs, too, but Emacs is more about learning vast sets of 'chords' of hotkeys - Control-x Control-s is save, et cetera - so that you can do anything from save the file to run the file as any give kind of program to running the file through various ports to turn on and off permissions and juggling multiple buffers. But only people like Richard Stallman need that kind of thing when they're editing text, I guess.)

... and there you have it.

If you turn your system on and off periodically:

You want to install the anacron package. I'll assume you're using FluxBuntu or another Debian-related system, since that seems likely. (What build of Linux are you running, by the way?)

The biggest difference between different breeds of Linux is their package manager - how they deal with new software packages that you choose to install. Debian is the largest and most carefully built and maintained Linux package, and it formed the basis of the Ubuntu project; it uses the dpkg system. In fact, I like Debian's package manager system best out of all that I've tried. It has a neat tool called the Advanced Packaging Tool (APT) which makes things very easy on the command line. For example, if you wanted to install Firefox in a Debian-based or -derived system, you type

apt-cache search firefox

and the APT will search for packages in the repository (a huge, gigantic collection of programs that the Debian project maintains) that mention or match your search criteria. You'll see that the package you want is called mozilla-firefox, so you can type

apt-get install mozilla-firefox

and Linux will automatically download and install Firefox for you. So now you know how to find the proper name of a program (apt-cache search) how to install it (apt-get install) once you've figured out the right name.

And, look, here's the man page for anacron. Basically, once you've installed anacron, follow the instruction above for if you have a system you don't turn off... only, instead of starting with

vim /etc/cron.daily/ntpdate

just start with

vim /etc/anacrontab

and, when you get into the file (which might already have some commands), just add a single line that says

/usr/sbin/ntpdate pool.ntp.org

and then you're done!

Sorry this is so long - I didn't want to make this too complicated, but if you're ready and willing to learn about Linux, well... all of this shouldn't really take you ten minutes, but it's worth learning about, especially since sometimes it's hard to know where to find this stuff out.
posted by koeselitz at 4:24 PM on March 8, 2009


If you have the proper timezone files and such, there shouldn't be any delay in changing the reported time when daylight savings starts/ends. The actual time isn't change, just the hour offset it uses to display your time.

Also, if your computer is connected to the internet reasonably often, don't bother with that mess with ntpdate. You want to install the ntpd daemon (the package is called ntp in Debian). It keeps a daemon running that syncs with the pool of ntp servers as needed to make sure your computer is never more than a particular fraction of a second.

The only time to run the ntpdate program by itself is if your clock is too far out of sync for ntpd to run. So, if you're 30 minutes off, run ntpdate once to sync and then make sure ntpd is running and you're good to go. (This article has the default Debian config file that works fine if you have any trouble setting it up.)

But almost any distro should have a package of ntp that works great out of the box.
posted by skynxnex at 6:43 PM on March 8, 2009 [1 favorite]


FWIW, I've decided skynxnex is right, and abandoned my cron job for just running ntpd (the 'ntp' package in ubuntu; 'ntp-simple' in some distros) on my nearly-always-on machines. I've configured it with tallus' list of North American ntp pool servers.
posted by Zed at 8:16 AM on March 9, 2009 [1 favorite]


« Older Buffalo Terastation   |   "These kids have to swim across a piranha-infested... Newer »
This thread is closed to new comments.