Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

1 votes
1 answers
2586 views
Orange Pi Zero: Wrong Date and Time even given Internet Access
I am using Orange Pi Zero and running Armbian Stretch OS 5.59 on it. Problem is, it is giving wrong date and time even in the presence of the Internet. I have tried restarting "ntp" service but to no avail. I have also tried rebooting, but the same annoying result. I have already set the right timez...
I am using Orange Pi Zero and running Armbian Stretch OS 5.59 on it. Problem is, it is giving wrong date and time even in the presence of the Internet. I have tried restarting "ntp" service but to no avail. I have also tried rebooting, but the same annoying result. I have already set the right timezone which is PKT, but it shouldn't matter. So what do I need to do or change? Thank you.
Saad (17 rep)
Nov 27, 2018, 08:36 AM • Last activity: Jul 19, 2025, 08:07 AM
0 votes
3 answers
497 views
Does the time command include the memory claimed by forked processes?
I want to benchmark some scripts with the `time` command. I am wondering if this command catches child processes' memory usage. ``` command time -f '%M' python my_script.py ``` If not, what are my options? Is `valgrind` suitable for this purpose? I also don't want to double count copy-on-write memor...
I want to benchmark some scripts with the time command. I am wondering if this command catches child processes' memory usage.
command time -f '%M' python my_script.py
If not, what are my options? Is valgrind suitable for this purpose? I also don't want to double count copy-on-write memory that is not actually filling up space.
HappyFace (1694 rep)
Jan 19, 2022, 12:29 PM • Last activity: Jul 13, 2025, 01:44 PM
12 votes
7 answers
56949 views
How to get system time with microsecond Resolution
I want to know current system time with microsecond Resolution. `date +%s` returns Time in seconds since epoch(1-1-1970). How can I get time in microseconds Resolution. How much delay is in querying this value? By delay I mean suppose at time `t` secs i query and it gives me value `t + t'` what is `...
I want to know current system time with microsecond Resolution. date +%s returns Time in seconds since epoch(1-1-1970). How can I get time in microseconds Resolution. How much delay is in querying this value? By delay I mean suppose at time t secs i query and it gives me value t + t' what is t' ?
My Use case: I am recording Videos using multiple Raspberry Pis simulatenously. Now I want to timestamp each frame of videos so that I can align them. Currently for timestamp it's using boot time(time since boot). Boot time is accurate but it's different for each Raspberry Pi. I have configured all Pi's to a NTP Server thus all have same System time. So basically I want the timestamp of System time not Boot Time. How can I do that ?
Coderaemon (229 rep)
May 21, 2015, 10:23 AM • Last activity: Jul 11, 2025, 10:46 AM
4 votes
2 answers
2242 views
Make date change permanent in EC2
How can I manually set date and time to future in EC2 instance and make it permanent, so it won't reset after reboot ? I can change date using this command: $ sudo timedatectl set-time "2017-12-09 16:00:00" $ timedatectl Local time: Sat 2017-12-09 16:00:01 UTC Universal time: Sat 2017-12-09 16:00:01...
How can I manually set date and time to future in EC2 instance and make it permanent, so it won't reset after reboot ? I can change date using this command: $ sudo timedatectl set-time "2017-12-09 16:00:00" $ timedatectl Local time: Sat 2017-12-09 16:00:01 UTC Universal time: Sat 2017-12-09 16:00:01 UTC RTC time: Sat 2017-12-09 16:00:02 Time zone: Etc/UTC (UTC, +0000) Network time on: no NTP synchronized: no RTC in local TZ: no OS on EC2: $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.3 LTS Release: 16.04 Codename: xenial What else should I do to make this permanent ? The purpose of this adjustment is to set the date to future, so I can test few things.
Michal Przybylowicz (471 rep)
Nov 2, 2017, 01:58 PM • Last activity: Jul 6, 2025, 01:08 AM
1 votes
1 answers
1916 views
Printing milliseconds with GNU time
I am using GNU time for benchmarking and would like to measure real, user and sys time to the nearest millisecond. That is, I want to measure seconds to 3 decimal places, not the default 2. Does GNU time offer such an option?
I am using GNU time for benchmarking and would like to measure real, user and sys time to the nearest millisecond. That is, I want to measure seconds to 3 decimal places, not the default 2. Does GNU time offer such an option?
Jacob Baird (11 rep)
Aug 16, 2019, 03:44 PM • Last activity: Jun 7, 2025, 03:05 PM
21 votes
7 answers
74131 views
Find last shutdown time
This is the command I am using: last -x|grep shutdown | head -1 but it's giving me the duration with +2 hours: shutdown system down 3.14-1-amd64 Mon Jul 21 08:43 - 22:19 (13:36) the last shutdown time (08:43) is correct, but the startup time (22:19, should be 20:19) is incorrect. Is there a better c...
This is the command I am using: last -x|grep shutdown | head -1 but it's giving me the duration with +2 hours: shutdown system down 3.14-1-amd64 Mon Jul 21 08:43 - 22:19 (13:36) the last shutdown time (08:43) is correct, but the startup time (22:19, should be 20:19) is incorrect. Is there a better command to check how long ago the PC was shutdown? or is my DST settings or something else causing this? PS: I am using Debian testing *(Linux rig 3.14-1-amd64 #1 SMP Debian 3.14.12-1 (2014-07-11) x86_64 GNU/Linux)*
şaloma (541 rep)
Jul 21, 2014, 07:11 PM • Last activity: Jun 6, 2025, 04:20 AM
-1 votes
1 answers
35 views
Merge two different times in cron format
I want to combine two different times which are in cron format into single time in bash shell script: e.g. ``` time1 = 15 03 * * 1-5 time2 = 15 03 * * 6 ``` result should be ``` 15 03 * * 1-6 ``` or e.g. ``` time1 = 00 05 * * 1-3 time2 = 00 05 * * 3-5 ``` result should be ``` 00 05 * * 1-5 ``` I can...
I want to combine two different times which are in cron format into single time in bash shell script: e.g.
time1 = 15 03 * * 1-5 
time2 = 15 03 * * 6
result should be
15 03 * * 1-6
or e.g.
time1 = 00 05 * * 1-3 
time2 = 00 05 * * 3-5
result should be
00 05 * * 1-5
I can ignore time part for now and only consider day of the week.
Vishal (1 rep)
May 20, 2025, 12:39 PM • Last activity: May 20, 2025, 12:56 PM
0 votes
2 answers
225 views
how and when does Linux read or change hardware (BIOS) clock
Scenario: - a Dell R740 server for example whose BIOS clock is first set, and it is set to UTC time but incorrectly and it is off 30 minutes. Then, a clean installation of Linux is performed (Redhat-8.10) and during installation the timezone is chosen, `New York` so EST. After installation, the time...
Scenario: - a Dell R740 server for example whose BIOS clock is first set, and it is set to UTC time but incorrectly and it is off 30 minutes. Then, a clean installation of Linux is performed (Redhat-8.10) and during installation the timezone is chosen, New York so EST. After installation, the time as presented in Linux via date is the correct local time but off 30 minutes, if we reference a peek at *time.gov* for correct time. There is no network connection to this server and no NTP/chrony is set up. - My observation is, if I manually adjust time to be correct (referencing time.gov from a different computer or my phone) by doing date mmddhhmm and then reboot, Linux reads the BIOS clock and then after booting the time in Linux is off 30 minutes again. - On my home computer which has an asrock motherboard and 2 different SSD's one for win10 the other for RHEL-8.10 Linux, and an internet connection, my BIOS clock is set to local time and I use win10 most of the time (and windows had NTP active). On the times I boot Linux, the time in Linux is the correct local time as presented by date however when I shutdown and then run windows the time in windows is then off by 4 or 5 hours; I am EST/EDT timezone. Also: > Windows expects the hardware clock to give “local time” by default. The reason is, according to Microsoft, so that users are not confused in BIOS menu; this is from a github page statement. Getting Windows to recognize BIOS (real-time-clock) as UTC apparently requires "tweaking" --- - What is the deal with how Linux deals with the BIOS clock? - **Am I expected** to use hwclock ? - What's the proper convention regarding what the BIOS clock is set to, UTC or local? - I seem to experience two different behaviors of Linux where it assumes on a Dell {enterprise style} server that the BIOS clock is UTC but on my cheap home asrock it is set to local time; And playing at home setting my asrock bios clock to UTC causes way more problems. - **What are files in Linux** dealing with this, to understand what Linux is going to do regarding time? Does it always reference the BIOS clock upon boot, and where is it specified in Linux for what timezone it should assume the BIOS clock to be in?
ron (8647 rep)
Apr 30, 2025, 01:59 PM • Last activity: Apr 30, 2025, 09:06 PM
0 votes
1 answers
93 views
why non network (no NTP) computer does not keep accurate time
what causes a computer to not keep accurate time? case in point a Dell server, r540/640/740 type having RHEL-8.10 installed, no network connection. It is standalone, there is no NTP or chrony in use, and time had been manually set in Linux via `date mmddhhmm` to the current time per my watch which I...
what causes a computer to not keep accurate time? case in point a Dell server, r540/640/740 type having RHEL-8.10 installed, no network connection. It is standalone, there is no NTP or chrony in use, and time had been manually set in Linux via date mmddhhmm to the current time per my watch which I manually set looking at *time.gov*. After sitting powered on an idle for maybe month, time on the standalone server is off by 30 minutes. Why? Is it a hardware issue, or is it a Linux [software] issue? My 20 year old battery powered wristwatch, and my 1980's era GE bedside alarm clock keeps way more accurate time. hwclock --show --verbose hwclock from util-linux 2.32.1 System Time: 1745946822.667986 Trying to open: /dev/rtc0 Using the rtc interface to the clock. Last drift adjustment done at 0 seconds after 1969 Last calibration done at 0 seconds after 1969 Hardware clock is on UTC time Assuming hardware clock is kept in UTC time. Waiting for clock tick... ...got clock tick Time read from Hardware Clock: 2025/04/29 17:13:43 Hw clock time : 2025/04/29 17:13:43 = 1745946823 seconds since 1969 Time since last adjustment is 1745946823 seconds Calculated Hardware Clock drift is 0.000000 seconds 2025-04-29 13:13:42.873561-04:00
ron (8647 rep)
Apr 29, 2025, 04:10 PM • Last activity: Apr 30, 2025, 05:04 AM
5 votes
2 answers
5711 views
Why I can't use the time command in verbose mode without specifying the whole command path?
Given that... ~$ which time time is a shell keyword time is /usr/bin/time Why this works? ~$ /usr/bin/time --verbose ./some_script.sh Command being timed: "./some_script.sh" User time (seconds): 0.00 System time (seconds): 0.01 Percent of CPU this job got: 51% Elapsed (wall clock) time (h:mm:ss or m...
Given that... ~$ which time time is a shell keyword time is /usr/bin/time Why this works? ~$ /usr/bin/time --verbose ./some_script.sh Command being timed: "./some_script.sh" User time (seconds): 0.00 System time (seconds): 0.01 Percent of CPU this job got: 51% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.03 Average shared text size (kbytes): 0 Average unshared data size (kbytes): 0 Average stack size (kbytes): 0 Average total size (kbytes): 0 Maximum resident set size (kbytes): 4572 Average resident set size (kbytes): 0 Major (requiring I/O) page faults: 1 Minor (reclaiming a frame) page faults: 1548 Voluntary context switches: 3 Involuntary context switches: 7 Swaps: 0 File system inputs: 48 File system outputs: 0 Socket messages sent: 0 Socket messages received: 0 Signals delivered: 0 Page size (bytes): 4096 Exit status: 0 And why this doesn't? ~$ time --verbose ./some_script.sh --verbose: no se encontró la orden real 0m0.124s user 0m0.101s sys 0m0.022s
matiascelasco (151 rep)
Aug 21, 2015, 03:18 AM • Last activity: Apr 29, 2025, 06:14 AM
4 votes
1 answers
2679 views
Who sets date/time automatically from the hardware clock at boot?
When Linux is booting, the current time must be fetched from a RTC chip and then set to Linux system date/time. I can do this manually by running `hwclock --hctosys`. But where exactly does this happen automatically at boot time? Is there a process taking care of this? Does the kernel do this job?
When Linux is booting, the current time must be fetched from a RTC chip and then set to Linux system date/time. I can do this manually by running hwclock --hctosys. But where exactly does this happen automatically at boot time? Is there a process taking care of this? Does the kernel do this job?
arminb (251 rep)
Oct 13, 2021, 02:47 PM • Last activity: Feb 11, 2025, 02:09 AM
75 votes
1 answers
123839 views
How do you time how long a command took to run?
How would you find out how long a running process took to complete? Example: date; dd bs=1m if=/foo of=bar; date ^This example only has 1 second of resolution. Any shell is acceptable.
How would you find out how long a running process took to complete? Example: date; dd bs=1m if=/foo of=bar; date ^This example only has 1 second of resolution. Any shell is acceptable.
spuder (18573 rep)
Aug 13, 2013, 10:15 PM • Last activity: Jan 27, 2025, 05:25 PM
6 votes
3 answers
610 views
bash history that stores execution time?
Is it possible to have your bash history save the **total execution time** of every command you run? i.e. as if every command were prefaced with 'time' and the result was stored in the history along with the command? clarification: I already know that you can add a timestamp of when the command was...
Is it possible to have your bash history save the **total execution time** of every command you run? i.e. as if every command were prefaced with 'time' and the result was stored in the history along with the command? clarification: I already know that you can add a timestamp of when the command was started - but I would like to know the *total execution time*, not just when it was started.
slashdottir (169 rep)
Dec 5, 2016, 03:09 PM • Last activity: Jan 14, 2025, 08:50 AM
0 votes
1 answers
156 views
Do I still need to set my server's time zone to UTC?
OS is Raspberry Pi OS 12. It looks like `timedatectl` shows the date both in UTC and my local timezone. Since it looks like the OS keeps track of UTC explicitly, is there any reason to not set the timezone to where the server is physically located? In the past I've always seen the advice "always use...
OS is Raspberry Pi OS 12. It looks like timedatectl shows the date both in UTC and my local timezone. Since it looks like the OS keeps track of UTC explicitly, is there any reason to not set the timezone to where the server is physically located? In the past I've always seen the advice "always use UTC for servers" but since timedatectl seems to keep track of UTC, perhaps this advice is now outdated. I did find this post also: https://unix.stackexchange.com/questions/741976/should-i-still-use-utc-for-all-my-servers but didn't see timedatectl mentioned.
cat pants (167 rep)
Dec 31, 2024, 01:59 AM • Last activity: Dec 31, 2024, 03:45 AM
124 votes
8 answers
298054 views
Why is scp so slow and how to make it faster?
I'm trying to copy a batch of files with `scp` but it is very slow. This is an example with 10 files: $ time scp cap_* user@host:~/dir cap_20151023T113018_704979707.png 100% 413KB 413.2KB/s 00:00 cap_20151023T113019_999990226.png 100% 413KB 412.6KB/s 00:00 cap_20151023T113020_649251955.png 100% 417K...
I'm trying to copy a batch of files with scp but it is very slow. This is an example with 10 files: $ time scp cap_* user@host:~/dir cap_20151023T113018_704979707.png 100% 413KB 413.2KB/s 00:00 cap_20151023T113019_999990226.png 100% 413KB 412.6KB/s 00:00 cap_20151023T113020_649251955.png 100% 417KB 416.8KB/s 00:00 cap_20151023T113021_284028464.png 100% 417KB 416.8KB/s 00:00 cap_20151023T113021_927950468.png 100% 413KB 413.0KB/s 00:00 cap_20151023T113022_567641507.png 100% 413KB 413.1KB/s 00:00 cap_20151023T113023_203534753.png 100% 414KB 413.5KB/s 00:00 cap_20151023T113023_855350640.png 100% 412KB 411.7KB/s 00:00 cap_20151023T113024_496387641.png 100% 412KB 412.3KB/s 00:00 cap_20151023T113025_138012848.png 100% 414KB 413.8KB/s 00:00 cap_20151023T113025_778042791.png 100% 413KB 413.4KB/s 00:00 real 0m43.932s user 0m0.074s sys 0m0.030s The strange thing is that the transfer rate is about 413KB/s and the file size is about 413KB so really it should transfer one file per second, however it's taking about 4.3 seconds per file. Any idea where this overhead comes from, and is there any way to make it faster?
laurent (2068 rep)
Oct 23, 2015, 01:34 PM • Last activity: Nov 26, 2024, 02:59 PM
2 votes
1 answers
2338 views
"export TZ=`date +%Z`" leads to confusing output of "date"
I recently noticed the following (strange) behavior: user@pc:~$ date Mi 21. Jun 12:03:10 CEST 2017 user@pc:~$ date +%Z CEST user@pc:~$ export TZ=`date +%Z` user@pc:~$ date Mi 21. Jun 10:03:30 CEST 2017 user@pc:~$ date +%Z CEST Thus, after setting the TZ environment variable to the current system tim...
I recently noticed the following (strange) behavior: user@pc:~$ date Mi 21. Jun 12:03:10 CEST 2017 user@pc:~$ date +%Z CEST user@pc:~$ export TZ=date +%Z user@pc:~$ date Mi 21. Jun 10:03:30 CEST 2017 user@pc:~$ date +%Z CEST Thus, after setting the TZ environment variable to the current system time zone, the clock is 2 hours delayed. It looks like UTC (CEST-2hours is UTC). If I now set TZ to other values, the clock remains unchanged: user@pc:~$ export TZ=UTC user@pc:~$ date Mi 21. Jun 10:07:09 UTC 2017 user@pc:~$ export TZ=PDT user@pc:~$ date Mi 21. Jun 10:07:19 PDT 2017 However, when I set TZ to CEST-2, it works fine again. I am a bit confused user@pc:~$ export TZ=CEST-2 user@pc:~$ date Mi 21. Jun 12:28:16 CEST 2017 I am working on xUbuntu 16.04 but this behavior is reproducible on a OpenSUSE 42.2 System. It seems to me that a time zone "ABC+X" is always considered as "UTC+X" when there is no /usr/share/zoneinfo/ABC file (thanks DevilaN for the comment). The string "ABC" is than only inserted into the date string, which is printed out. Questions: 1. Is the assumption described above correct? 2. Why does date print out a time zone abbreviation that is not supported (i.e. not available in /usr/share/zoneinfo)?
daniel.heydebreck (162 rep)
Jun 21, 2017, 10:34 AM • Last activity: Oct 14, 2024, 05:14 AM
1 votes
1 answers
257 views
How to determine if file has been modified in the last x seconds
I want to determine if a file has been modified in the last x seconds on MacOS or Debian etc. is_file_older_than() { seconds="$1" file="$2" echo "The file $file" modified_secs="$(date -r "$file" +%s)" current_secs="$(date +%s)" diff="$(expr "$current_secs" - "$modified_secs")" if [[ "$diff" -gt "$se...
I want to determine if a file has been modified in the last x seconds on MacOS or Debian etc. is_file_older_than() { seconds="$1" file="$2" echo "The file $file" modified_secs="$(date -r "$file" +%s)" current_secs="$(date +%s)" diff="$(expr "$current_secs" - "$modified_secs")" if [[ "$diff" -gt "$seconds" ]]; then return 0 fi return 1 } if is_file_older_than 3 "$BASH_SOURCE"; then echo 'old' else echo 'young' fi but I am trouble verifying if it's working 100% and if there's anything unreliable - it looks like it's working
Alexander Mills (10734 rep)
Aug 28, 2019, 10:02 PM • Last activity: Oct 13, 2024, 03:51 PM
2 votes
1 answers
97 views
Making the locale time format more compact
`dmesg -T` gives human readable time format, and I want to make it more compact, from this [Пт мар 12 09:18:54 2021] wlan0: associated to this [12.03.21 09:18:54] wlan0: associated I'm using ru_RU.UTF-8 locale and the current date/time format looks like dmesg uses this locale settings too. So I have...
dmesg -T gives human readable time format, and I want to make it more compact, from this [Пт мар 12 09:18:54 2021] wlan0: associated to this [12.03.21 09:18:54] wlan0: associated I'm using ru_RU.UTF-8 locale and the current date/time format looks like dmesg uses this locale settings too. So I have edited /usr/share/i18n/locales/ru_RU like this: date_fmt "%d.%m.%y %T" d_t_fmt "%d.%m.%y %T" d_fmt "%d.%m.%y" t_fmt "%T" But after locale-gen I don't see any differences in dmesg -T date/time format, it's still the same. Rebooting does not help too. The output of date command have changed how I wanted: root@PC1:~# date 12.03.21 09:42:17 I'd like to understand where dmesg gets settings for date/time format and how to change them. Operating System: Debian GNU/Linux 10 (buster) Kernel: Linux 4.19.0-14-amd64 I know about --time-format and all corresponding printf possibilities to change output of dmesg, but I want to have more compact date systemwide. I thought Linux has single point of locale settings, and I wonder why editing of locales do not do the trick with dmesg.
5007060 (21 rep)
Mar 12, 2021, 09:44 AM • Last activity: Oct 8, 2024, 05:11 AM
1 votes
3 answers
234 views
Get user's login duration time without time of locked screen
I'd like to get information about "utilization time" of users on linux sytems for specific days. This means the time, an user has an unlocked screen. In contrast the command `ac` displays the whole time, a user is logged in, including the time with locked screen or standby. As far as I knows, the id...
I'd like to get information about "utilization time" of users on linux sytems for specific days. This means the time, an user has an unlocked screen. In contrast the command ac displays the whole time, a user is logged in, including the time with locked screen or standby. As far as I knows, the idle time displayed by who command differs from the time with unlocked screen. So that's apparently not the solution. The open source progam *Timekpr* displays the wanted information, but only for the current week. May be it is possible to extract the code for that calculation. However, my programming skills are too bad for that.
Richard (11 rep)
Mar 28, 2023, 09:29 AM • Last activity: Sep 26, 2024, 05:40 PM
4 votes
2 answers
364 views
Invalid date when setting one computer's clock from another
I have the following code in a Bash script, which takes the current date/time and sets it via SSH on a target computer: ``` ssh @ "date --set '$(date)'" ``` This was working fine with various Ubuntu distros, but recently the target changed to another flavour of Linux and I get "invalid date" error....
I have the following code in a Bash script, which takes the current date/time and sets it via SSH on a target computer:
ssh @ "date --set '$(date)'"
This was working fine with various Ubuntu distros, but recently the target changed to another flavour of Linux and I get "invalid date" error. What is the correct way to do this, which should work for any version of Linux?
Richard Whitehead (161 rep)
Sep 24, 2024, 01:18 PM • Last activity: Sep 24, 2024, 08:30 PM
Showing page 1 of 20 total questions