In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to use the date command to set the system date and time in Linux. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
Display system date
To display the system date, simply enter:
$date Thu Dec 5 22:55:41 WIB 2013
Format display date
Dates come in many formats. If you don't like the default format, you can change it. You might think, "Why do I need to change the format? the default output is enough for me."
Yes, you are right, but when you are programming, the default output may not meet your needs, so you need some custom output.
Date and time output format for RFC 2822
$date-R Thu, 05 Dec 2013 23:40:53 + 0700
The format of RFC 2822 is like this: week, day-month-year, hour: minute: second time zone
The time zone + 0700 is equivalent to GMT + 7.
By default, date uses the time zone defined in / etc/localtime. Valid time zone data is defined in / usr/share/timezones.
Displays or sets coordinated Universal time
On Wikipedia, UTC means
The world's major clock and time standards. This is one of several very similar replacements for Green position Standard time.
Displays the date and time in UTC format, using the-u parameter
$date-u Thu Dec 5 16:45:58:UTC 2013
Use formatting options
To customize your date format, use the plus sign (+)
$date + "Day:% d Month:% m Year:% Y" Day: 05 Month: 12 Year: 2013$ date +% D 12-05-13
% D format is year / month / day format.
You can output the name of the date if you want. Here are some examples:
$date + "a% b% d% y" Fri 06 Dec 2013$ date + "A% B% d% Y" Friday December 06 2013$ date + "A% B% d% Y% T" Friday December 06 00:30:37$ date + "A% B-%d-%Y% c" Friday December-06-2013 12:30:37 AM WIB
There are also a lot of date formats. Just enter:
$date-help
Or
$man date
To display the syntax and parameters of the date command.
Basically, the date command translates all formats that begin with the percent sign (%) and outputs everything in quotation marks ("").
Set system date and time
Usually, you want your system date and time to be set automatically. If for some reason you want to modify it manually, we can use this command.
# date-set= "20140125 09:17:00"
This will set your current system date and time to January 25, 2014 and 09:17:00 AM. Please note that you must have root privileges to do this. Or you will get such a mistake.
Date: cannot set date: Operation not permitted Sat Jan 25 09:17:00 WIB 2014
Reset your time
You can use this technique if you want to reset your system date and time to the original value.
# hwclock Fri 06 Dec 2013 03:44:10 AM WIB-0.314082 seconds
This time set your system date and time to the output of the hwclock command.
Use the date command in a script
Remember when I said why you need to change the output of date? One answer is that you may need to program. Let's look at an example under the bash script.
$vi display.date #! / bin/bash DATETIME=$ (date + "DATE:% a% b-%d-%Y TIME:% T WEEK NUMBER:% W") echo $DATETIME
Save and run it:
$. / display.date DATE: Fri Dec-06-2013 TIME: 03:08:19 WEEK Number: 40
If you find an error message about permission denial, type:
$chmod 755 display.date
Using date in the backup process
Another example is the use of date in your backup process.
$date +% F 2013-12-06$ tar zcfv / daily_backup/backup- `date +% F`.tar.gz / home/pungki/Documents
It compresses the folder / home/pungki/Documents into a file called backup-2013-12-06.tar.gz located in / daily_backup folder. Note: embed other commands on the command line through "`Command'". This character is not a single quotation mark, but the symbol with the same key position as the tilde. )
This is how to use the date command to set the system date and time in the Linux shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.