- Display Date And Time In Linux
- Syntax
- Display date and time in Linux using the timedatectl
- TZ environment variable
- GUI Tool: Time Administration
- How to change date and time settings with Gnome based Linux desktop
- Conclusion
- How to Check Execution Time of a Process in Linux
- Gnomon
- Installing Gnomon
- Using Gnomon
- Available Options are:
- Check running process time using ps
- Using time command on Ubuntu
- How to Check Timezone in Linux
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- How To Set/Change Time, Date And Timezone In Linux?
- 1) How To Check Current Date, Time And Timezone Information In Linux?
- 2) How To Set/Change Date And Time In SysVinit Systems?
- 3) How To Set/Change Date And Time In systemd Systems?
- 4) How To Change The TimeZone In systemd Systems?
- 5) How To Change The TimeZone In RHEL 6/CentOS 6 Systems?
- 6) How To Automatically Adjust Your Linux System Clock?
Display Date And Time In Linux
H ow do I display date and time in Linux using the command line and GUI options?
To display date and time under Linux operating system using command prompt use the date command. It can also display the current time / date in the given FORMAT. We can set the system date and time as root user too.
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | No |
Requirements | Linux with the terminal application |
Est. reading time | 3 minutes |
Syntax
Open a terminal and type the following command:
date
You can format the date as follows in dd-mm-yy format:
date +»%d-%m-%y»
Simply display the current time:
date «+%T»
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
To print the date of the day before yesterday, run:
date —date=’2 days ago’
Want to see the day of year of Christmas in the current year? Try:
date —date=’25 Dec’ +%j
Display the current full month name and the day of the month:
date ‘+%B %d’
Display date and time in Linux using the timedatectl
Most modern Linux distro with systemd use the timedatectl command. It is used to query and change the system clock and its settings, and enable or disable time synchronization services. All you have to do is type the following command:
$ timedatectl
TZ environment variable
The TZ environment tells Linux what time zone you are in. Many times when you want to change your time zone temporarily. For example, you might want to print the current date and time in “America/Los_Angeles” timezone even though you are in “Europe/London”. So we can set TZ, give a command like as follows when using TCSH/CSH:
setenv TZ timezone
For BASH/KSH/SH (see export command:
TZ=timezone; export TZ
Another option:
TZ=»America/Los_Angeles» date
TZ=»Asia/Tokyo» date
Use the following command to print a list of all timezones:
timedatectl list-timezones
timedatectl list-timezones | more
## filter out data using the grep command/egrep command ##
timedatectl list-timezones | grep -i Hong_kong
timedatectl list-timezones | grep -i paris
timedatectl list-timezones | grep -E -i ‘paris|london|kolkata’
The TZ Environment Variable on Linux
GUI Tool: Time Administration
The Time Administration Tool allows you to set the time, date and timezone of your system, as well as setting any time server to synchronize your local time server. Type the following command to start time admin tool:
sudo time-admin
## OR ##
time-admin
Fig.01: Linux Date and Time Administration Tool
How to change date and time settings with Gnome based Linux desktop
First, you need to Settings in Activities and then click Details in the sidebar. Make sure you click Date & Time in the sidebar to open the panel:
Conclusion
In this quick tutorial, you learned about the date command that you can use to see or change the date/time under Linux operating systems. We further explained how to use the GUI tools too. The date command has many more options. See man page by typing the following man command:
$ man date
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
How to Check Execution Time of a Process in Linux
Have you been wondering how you can find an execution time of a process in Linux or Unix system?. This guide will show you a number of tools which comes in handy when trying to find execution time of a process in Linux.
At times you may have to work on slow executing processes or having a slow internet or running a program that you need to track its execution time. Let’s look at the top tools that you should try out for this. Every command shown in this guide has been tested on Ubuntu 16.04 server and on CentOS 7.
Gnomon
Gnomon is a utility used to annotate console logging statements with timestamps and find slow processes on a Linux system. This tool is useful for long-running processes where you’d like a historical record of what’s taking so long.
Installing Gnomon
Since Gnomon is a tool written in Node.js, you need Node.js installed on your system so that you can install gnomon with npm package manager. Once you have npm tool present on your Linux system, then proceed to install them using:
Using Gnomon
To prepend a timestamp to each line, you need to pipe the command to gnomon. It will indicate how long the process took to execute. By default, gnomon will display the seconds elapsed between each line, but that is configurable.
Take a look at below example which prints the time taken to do 5 times ping request to google DNS server.
The total time elapsed is 3.3842s.
Available Options are:
Below is a list of options available:
Type of timestamp to display.
elapsed-line: Number of seconds that displayed line was the last line.
elapsed-total: Number of seconds since the start of the process.
absolute: An absolute timestamp in UTC.
-f | —format=»format»: Format the absolute timestamp, using PHP date format strings. If the type is elapsed-line or elapsed-total, this option is ignored. The default format is «H:i:s.u O«
Example to disable real-time update:
-h | —high=seconds : High threshold
-m | —medium=seconds : Medium threshold. Works just like the high threshold described above, but colors the timestamp bright instead.
Check running process time using ps
You can use ps command to check the time a particular process has been running. You need to first find process ID then use it to find elapsed time.
To identify process ID, you can use a tool like pidof
Then use ps with options -o etime to find elapsed running time.
etime option displays elapsed time since the process was started, in the form [[DD-]hh:]mm: ss. So from above example, the process has been running for 5 days, 11 hours and 3 minutes. Use etimes option to get elapsed time in seconds.
This command option can also be used for multiple processes. The example below will display start time and the execution time of all processes on my Ubuntu server.
The output has 4 columns:
PID —> ID of the running process
STARTED —> The time the process was initially started
ELAPSED —> Total running time of the process
COMMAND —> Process executed command
Using time command on Ubuntu
The time command reports how long the command took to execute on a Linux system. You can install it if missing on Ubuntu system using:
time command Usage:
The output of time will have:
- The elapsed real time between command invocation and termination.
- The user CPU time.
- The system CPU time.
Consider below example to check disk usage of /root directory.
From the output, the actual time the command took to execute is 0m0.007s.
Let’s do one more, a ping to 8.8.8.8
The actual execution time is 2.059 seconds.
Now you know how to get the Linux Process execution time on Linux. The first method is ideal for interactive processes. For processes that run in the background, you can always get their execution time using ps command.
Источник
How to Check Timezone in Linux
In this short article, we will walk newbies through the various simple ways of checking system timezone in Linux. Time management on a Linux machine especially a production server is always an important aspect of system administration.
There are a number of time management utilities available on Linux such as date and timedatectl commands to get the current timezone of system and synchronize with a remote NTP server to enable an automatic and more accurate system time handling.
Well, let us dive into the different ways of finding out our Linux system timezone.
1. We will start by using the traditional date command to find out present timezone as follows:
Alternatively, type the command below, where %Z format prints the alphabetic timezone and %z prints the numeric timezone:
Find Linux Timezone
Note: There are many formats in the date man page that you can make use of, to alter the output of the date command:
2. Next, you can likewise use timedatectl, when you run it without any options, the command displays an overview of the system including the timezone like so:
More so, try to employ a pipeline and grep command to only filter the timezone as below:
Find Current Linux Timezone
3. In addition, users of Debian and its derivatives can display the content of the file /etc/timezone using cat utility to check your timezone:
Check Timezone of Linux
Important: For REHL/CentOS 7 and Fedora 25-22 users, the file /etc/localtime is a symbolic link to the timezone file under the directory /usr/share/zoneinfo/.
However, you can use date or timedatectl command to display the current time and timezone as well.
To change the timezone, create the symbolic link /etc/localtime to the appropriate timezone under /usr/share/zoneinfo/:
The flag -s enables creation of a symbolic link, otherwise a hard link is created by default and -f removes an existing destination file, which in this case is /etc/localtime.
For example, to change the timezone to Africa/Nairobi, issue the command below:
That’s all! Do not forget to share you thoughts about the article by means of the feedback form below. Importantly, you should look through this time management guide for Linux to get more insight into handling time on your system, it has simple and easy-to-follow examples.
Lastly, always remember to stay tunned to Tecmint for the latest and interesting Linux stuff.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
How To Set/Change Time, Date And Timezone In Linux?
If you missed to set the proper timezone, date and time while installing the OS. Don’t worry it can be changed at any point of time.
If we bought the server from some providers and they might have set the timezone based on their location.
Say for example, if you buy a server from USA then they will build a system based on their GEO location.
If so, don’t worry you can simply change the timezone and date formats as per your requirement using the below commands on your Linux Box.
In this article, i have covered all the possible methods with all Major Linux Distribution such as CentOS, Redhat (RHEL), Fedora, Ubuntu, Debian, Mint & openSUSE systems.
Also, we have updated the information based on the system manager such as SysVinit and systemd. Timezone is controlled by /etc/localtime file.
The below files are belongs to timezone on Linux.
- /usr/share/zoneinfo: This directory contains timezone files.
- /etc/localtime: This file is symlink with timezone file.
- /etc/timezone: This file is holding timezone name on debian based systems.
- /etc/sysconfig/clock: This file is holding timezone name on RHEL based systems.
1) How To Check Current Date, Time And Timezone Information In Linux?
Use the following commands to check the current date, time and timezone information in Linux systems.
To check current system date and time.
To display current system date and time with UTC format.
Run the following command to display Hardware Clock (RTC).
To check the timezone on SysVinit systems.
We can sell all the details together in the single command for systemd systems. See the details below.
2) How To Set/Change Date And Time In SysVinit Systems?
Use the following commands to set or change the time and date as you wish in Linux SysVinit systems. If you requires locale’s then you can set accordingly.
Common Syntax:
To set new date and time in one shot, use the following format.
You can double confirm this by running date command once again.
To set only time, use the following format.
To set only date, use the following format.
To Set time with locale’s.
To set the hardware clock to local time.
To set the hardware clock to UTC time.
3) How To Set/Change Date And Time In systemd Systems?
Use the following commands to set or change the time and date as you wish in Linux systemd systems.
Common Syntax:
To change the new date and time in one shot, use the following format.
To set only time, use the following format.
To set only date, use the following format.
Use the following format to set RTC time.
4) How To Change The TimeZone In systemd Systems?
For systemd system, use the timedatectl command to change the timezone. Navigate to the following url to change the timezone in Linux.
If you would like to restart the timedatectl service, use the following command.
Run the following command to verify the new timezone.
5) How To Change The TimeZone In RHEL 6/CentOS 6 Systems?
For RHEL/CentOS systems, use the following command to change the timezone.
Run the following command to check the new timezone in RHEL/CentOS systems.
6) How To Automatically Adjust Your Linux System Clock?
If you would like to sync your Linux system clock to remote NTP server then you have configure it.
To do so, navigate the following urls because we had written an detailed articles about these in the past.
Источник