Skip to content Gå til innhold


How to set the date on your Linux machine Slik angir datoen på din Linux-maskin

Linux

We recently ran an Vi har nylig kjørte en article Artikkel on the Linux “date” command. på Linux "date" kommandoen. It's a pretty cool command line tool that allows you to get your system's date and time in various formats. Det er en ganske kul kommandolinje-verktøy som lar deg få systemets dato og klokkeslett i ulike formater. What it also does is it allows you to set the machine's date and time. Hva den også gjør er det tillater deg å stille inn maskinen dato og klokkeslett. Let's look at a couple of ways to set the time and date on a Linux machine. La oss se på et par måter å angi klokkeslett og dato på en Linux-maskin. First, we'll look at how to do it using the “date” command, then I'll briefly introduce you to the NTP server in Linux and show you how you can sync your machine's clock to a clock running on the Internet. Først vil vi se på hvordan man gjør det ved hjelp av "date" kommandoen, så skal jeg kort introdusere deg til NTP-server i Linux og vise deg hvordan du kan synkronisere maskinens klokke til en klokke som kjører på Internett.

First, a brief recap on what the “date” command can do for you: Først en kort oppsummering av hva "date" kommandoen kan gjøre for deg:

# date # Dato
Mon Dec 22 22:35:58 IST 2008 Mon Dec 22 22:35:58 IST 2008

Now if you want to change the machine's date to 1:45 PM on Christmas day in the year 2008, here's how you would do it: Nå, hvis du vil endre maskinens dato til 1:45 på juledag i år 2008, her hvordan du ville gjøre det:

# date -s “25 DEC 2008 13:45:00″ # Date-s "25 DEC 2008 13:45:00»
Thu Dec 25 13:45:02 IST 2008 Thu Dec 25 13:45:02 IST 2008

This above command is pretty self-explanatory. Dette over kommandoen er ganske selvforklarende. But to make it clear, here's the breakup. Men for å gjøre det klart, her er oppløsningen. First comes the “date” command. Først kommer "date" kommandoen. Then you use the “-s” option, which stands for “set date”. Så kan du bruke "-s" alternativet, som står for "angitt dato". After that you enter the date you want to set in the following order. Etter at du angi dato du ønsker å sette i følgende rekkefølge. “Date Month Year Hours:Minutes:Seconds”. "Dato Måned År timer: minutter: sekunder». After entering this hit the return key. Når du har angitt denne treffer retur-tasten. The system should revert with the new date. Systemet skal gå med den nye datoen. Now you can enter the “date” command once again to make sure that the date is set right. Nå kan du gå inn på "date" kommandoen igjen for å kontrollere at datoen er satt riktig.

There are a number of other ways to do this same thing. Det finnes en rekke andre måter å gjøre det samme. As you might have read in my previous article about the “date” command, it is pretty versatile. Som du kanskje har lest i min forrige artikkel om "date" kommandoen, det er ganske allsidig. You can do something similar as what we just tried above with a slightly different syntax: Du kan gjøre noe lignende som det vi bare prøvd ovenfor med en litt annen syntaks:

# date +%Y%m%d -s “20081225″ # Date +% Y% m% d-s "20081225"

This will set the system's date to the 25th of December, 2008. Dette vil sette systemets dato til den 25. desember 2008.

The other method I use to set my computer's date is using the NTP server. Den andre metoden jeg bruker for å sette datamaskinen min dato er ved hjelp av NTP-server. NTP stands for Network Time Protocol. NTP står for Network Time Protocol. NTPd is a daemon that runs on most Linux machines. NTPd er en daemon som kjøres på de fleste Linux-maskiner. When configured correctly this daemon allows you to connect to a Time server over the network (your local network or the Internet) and synchronize the time. Når riktig konfigurert denne demonen lar deg koble til en Time-server over nettverket (det lokale nettverket eller Internett) og synkronisere tiden. It's very commonly used for production servers. Det er veldig ofte brukt for produksjon servere.

It's pretty likely that your Linux machine is already equipped with NTP. Det er ganske sannsynlig at Linux-maskinen er allerede utstyrt med NTP. If not, install it using your system's preferred installation method. Dersom ikkje, må du installere det med systemet ditt foretrukne installasjonsmetode.

Ubuntu users can use the following command: Ubuntu-brukere kan bruke følgende kommando:

# sudo apt-get install ntpdate Sudo apt-get install ntpdate

Fedora users can probably use this: Fedora brukere kan trolig bruke denne:

# yum install ntp # Yum installere ntp

Once NTPd is installed on your computer open the file /etc/ntp.conf in your favorite text editor. Når NTPd er installert på datamaskinen, åpne filen / etc / ntp.conf i din favoritt teksteditor. In this file locate a line containing the “server” parameter. I denne filen finner en linje som inneholder "server"-parameteren. Set it to the following address: Sett det til følgende adresse:

server pool.ntp.org server pool.ntp.org

Save the file and restart your NTP server. Lagre filen og starte NTP server.

# /etc/init.d/ntpd restart # / Etc / init.d / ntpd hvile

You can now synchronize your machine to the time server you just configured: Du kan nå synkronisere maskinen til tidsserveren du nettopp konfigurerte:

# ntpdate pool.ntp.org # Ntpdate pool.ntp.org
22 Dec 23:07:00 ntpdate[24328]: step time server 123.108.39.80 offset 172868.246157 sec 22 desember 23:07:00 ntpdate [24328]: trinn tidsserver 123.108.39.80 offset 172868,246157 sec

Now your machine will quickly talk to the time server you assigned it and get you the right time. Nå maskinen vil raskt snakke tidsserveren du tilordnet den og få deg til riktig tid. This way you know for sure that the time on your machine is accurately set. På denne måten vet du sikkert at tiden på maskinen er nøyaktig innstilt. It may be a good idea to run this command every once in a while to make sure you're on time. Det kan være lurt å kjøre denne kommandoen hver gang imellom for å sikre at du er på gang.

Posted in Posted in Linux Linux . .

Related Posts: Relaterte innlegg:

The Linux 'date' command Linux 'date' kommando
How to see a detailed history of the commands run in Linux Slik kan du se en detaljert historie om kommandoene kjøres i Linux
How to save the output of a Linux command to a file Hvordan lagre utdata fra en Linux-kommandoen til en fil
An introduction to the sudo command and configuration file En introduksjon til sudo-kommandoen og konfigurasjonsfil
Walkthrough: Time Machine for OS X 10.5 Leopard Walkthrough: Time Machine i OS X 10.5 Leopard

3 Responses 3 Svar

Stay in touch with the conversation, subscribe to the Holde kontakten med samtalen, abonnere på RSS feed for comments on this post RSS feed for kommentarer til dette innlegget . .

  1. noneck noneck says sier

    For my Debian boxes I usually use the following after a Net Install: For min Debian bokser som regel bruker jeg fulgte etter en Net Install:

    mv /etc/localtime /etc/localtime.bak mv / etc / Localtime / etc / localtime.bak

    ln -sf /usr/share/zoneinfo/America/Los_Anglese /etc/localtime ln-sf / usr / share / zoneinfo / Amerika / Los_Anglese / etc / Localtime

    /etc/init.d/ntpd restart / etc / init.d / ntpd hvile

    date dato

  2. myhnet myhnet says sier

    and if you want to save the time after restart, you need to use this command og hvis du vil lagre tiden etter hvile, må du bruke denne kommandoen
    hwclock –systohc hwclock-systohc

  3. serar says serar sier

    I'm using Arch linux and the ntpd daemon is located in /etc/rc.d/ntpd, but I didn't need to start it. Jeg bruker Arch linux og ntpd daemon ligger i / etc / rc.d / ntpd, men jeg trengte ikke å starte den. I just used: # ntpdate pool.ntp.org and it worked. Jeg brukte: # ntpdate pool.ntp.org og den arbeidet. However if you have the ntpd server running the update won't work. Men hvis du har ntpd serveren kjører oppdateringen vil ikke fungere.



Some HTML is OK Some HTML is OK

or, reply to this post via eller svare på dette innlegget via trackback styrekule . .