Tag Info

Hot answers tagged

14

I suggest to take a look at bash variable SECONDS: SECONDS: Each time this parameter is referenced, the number of seconds since shell invocation is returned. If a value is assigned to SECONDS, the value returned upon subsequent references is the number of seconds since the assignment plus the value assigned. Thus you can simply ...


12

To be able to time a subshell, you need the time keyword, not command. The time keyword, part of the language, is only recognised as such when entered literally. Even entering "time" won't work let alone $TIME (and would be taken as a call to the time command instead). You could use aliases here which are expanded before another round of parsing is ...


8

Prefix your command with /usr/bin/time and the time command will output the time it took the script to run. This is more portable than the using something bash specific.


7

It doesn't work because time is a shell keyword. There are external time binaries, but you don't appear to have one installed. This will likely work: nohup bash -c 'time sleep 2'


5

In bash: $ type -a time time is a shell keyword time is /usr/bin/time You called time, cause bash invoked time built in keyword instead of external /usr/bin/time command. time built in keyword does not have option -v. bash interpreted that you calling built in time on command -v, causing this error. Try: /usr/bin/time -v ls or: command time -v ls


5

The system clock and the hardware clock are not the same. The command hwclock -r should show you the time the hardware clock is set to. If it is incorrect, use the command hwclock -w to update it when the time is correct. If you dual boot with windows, you will want to use local time. Otherwise, you may want to set the harward clock to UTC with the ...


5

No, you should not be prompted for a password again. The script will be running as root due to the gksudo. In my experience, sudo never asks for password if you are already root (although I couldn't find this explicitly documented).


5

The usual solution to this problem is to put your time command in a group: $ { time wc test >wc.out; } 2>time.out


5

While using SECONDS and time will give you relative values. If you'd like to have absolute values for Auditing and Reporting Purposes as to when the script ran and when it completed, you might want to try something like this before and after your commands date '+%Y%m%d%H%M%S.%N' . This could also give you a better granularity as it can capture ...


4

You can run a command (including a shell and all of its children) with an arbitrary faster clock frequency by using the warp command from the ast-open package. It uses LD_PRELOAD, so won't work with setuid or setgid or (now relatively rare) statically-linked programs. From the warp man page: warp [ options ] date [ command [ arg ... ] ] warp ...


4

On Linux, the info is available in fields 14 to 17 of /proc/$pid/stat (see proc(5) for details): Fields are: 14: user time (in number of clock ticks) 15: sys time 16: user time of waited for children 17: sys time of waited for children (all the threads of a given process have the same values there) They are not directly reported by ps. ps reports 14 + ...


4

This is kind of hacky and unscriptable, but might get you what you're looking for. Firefox can run javascript via command line like so: firefox "javascript:alert(Date.now())" That will open Firefox and run javascript to pop up a message box containing the number of milliseconds in epoch time. You can get the number of milliseconds elapsed in epoch time ...


4

For this answer, I'll assume that there may be several elements working hard to set your time straight. Since I don't really want to wild-guess about which one is working against you, I'll try and give you an answer which should help you find it yourself instead. On a UNIX system, the clock can typically be set using the stime system call. As things ...


3

While an alias is one way to do it, this can be done with eval as well - it's just that you don't so much want to eval the command execution as you want to eval the command declaration. I like aliases - I use 'em all the time, but I like functions better - especially their ability to handle parameters and that they needn't necessarily be expanded in command ...


3

Use systemd-analyze built-in tool. You are especially interested in two options: blame and plot systemd-analyze blame systemd-analyze plot > graph.svg blame: Print list of running units ordered by time to init plot: Output SVG graphic showing service initialization


3

There's no foolproof way to tell. However, for log files, the change time (as opposed to the modification time) which you see in the output of stat may be the time at which the compressed file was created, because the filesystem attributes of these compressed files are rarely modified after their creation. For .gz files which were not created by compressing ...


3

With zsh: mutt -s "Log" -a /path/to/*.log(.om[1]) example@example.com That uses zsh glob qualifiers. While other shell globs can only generate filenames based on their name, in zsh, you can use those qualifiers ((.om[1]) above), to select based on file attributes (type, size, times, permissions...) or other criteria of your own, affect the order, apply ...


3

It's because the time in the first command is a shell keyword. The time in the second command is the executable. See the type output of time: $ type -a time time is a shell keyword time is /usr/bin/time The command unbuffer needs a program as argument not a shell keyword. It cannot interpret a shell keyword, this is a bash internal keyword. And the ...


3

From the section of execute_cmd.c of bash-4.2+dfsg that deals with TIMEFORMAT: if (*s == 'R' || *s == 'E') len = mkfmt (ts, prec, lng, rs, rsf); else if (*s == 'U') len = mkfmt (ts, prec, lng, us, usf); else if (*s == 'S') len = mkfmt (ts, prec, lng, ss, ssf); else { internal_error (_("TIMEFORMAT: `%c': invalid format character"), *s); free ...


3

Access: 2014-05-20 11:04:27.012146373 -0700 Modify: 2014-04-05 20:59:32.000000000 -0700 Change: 2014-05-20 11:04:22.405479507 -0700 Access: last time the contents of the file were examined. Modify: Last time the contents of the file were changed. Change: Last time the file's inode was changed. The change time includes things like modifying the ...


3

I don't think you can pause system time. Lots of programs wouldn't like it anyway, because they generally expect time to go forward. If you paused the time, then any program going into sleep would never wake up. I don't understand exactly what you're trying to do, but I suspect that faketime would do what you're after. It lets you run programs with a fake ...


2

An awk (mawk 1.3.3) solution: ls | awk -F'[_.]' '{printf "%s_%s\n", $2, $3}' | \ awk ' $0 > "2014-05-28_15:08:00" {print}' Gives: 2014-05-28_15:08:01 2014-05-28_15:08:09 2014-05-28_15:08:10 2014-05-28_15:08:11 2014-05-28_15:08:12 2014-05-28_15:08:13 2014-05-28_15:08:14 2014-05-28_15:08:22


2

A perl solution: $ perl -nle ' BEGIN {$t = "2014-05-28_15:08:00"} if (/_(.*?)\./) { print if $1 gt $t; } ' file job_2014-05-28_15:08:01.log job_2014-05-28_15:08:09.log job_2014-05-28_15:08:10.log job_2014-05-28_15:08:11.log job_2014-05-28_15:08:12.log job_2014-05-28_15:08:13.log job_2014-05-28_15:08:14.log job_2014-05-28_15:08:22.log ...


2

start a listening netcat in the background call firefox to connect it wait it with a wait bash builtin. finally kill everything nc -l 64738 & firefox http://127.0.0.1:64738 & wait <...yet to be solved that only the nc should be waited for...> killall firefox <..yet to be solved to not kill your girlfriends browser>


2

The time command will print its output to standard error, not standard output. So that's what you need to capture. Then, you need to capture the output of time and not the output of the command you are timing. Typically, this is done by grouping or running the commands in a subshell (in { } or ( ) respecitvely), redirecting the group's output to /dev/null ...


2

#!/bin/sh EPOCH='jan 1 1970' sum=0 for i in 00:03:34 00:00:35 00:12:34 do sum="$(date -u -d "$EPOCH $i" +%s) + $sum" done echo $sum|bc date -u -d "jan 1 1970" +%s gives 0. So date -u -d "jan 1 1970 00:03:34" +%s gives 214 secs.


2

The simplest way is to use the --printf option as suggested by @don_crissti: stat --printf='%A %h %U %G %s %.16y %n\n' .bashrc If, for whatever reason, you can't do that you can parse the output of `stat -c '%y': $ stat -c'%A %h %U %G %s %y %n' .bashrc | awk '{$7=substr($7,1,8); $8=""}1;' -rw-r--r-- 1 terdon terdon 9737 2015-02-01 18:12:18 .bashrc Or ...


2

Bash's built-in time returns the exit status of the command. You can test that fairly easily with time false; afterwards, echo $? prints 1 as expected. You can also test something with a different exit code to confirm other codes are preserved: $ time bash -c 'exit 42'; echo "Exit code: $?" real 0m0.002s user 0m0.000s sys 0m0.000s Exit code: 42


2

To me, NTP is the obvious answer. Reliable and consistent - assuming some sort of Internet connection, with an option that's enabled on many distributions to set the clock directly during the boot-up process. However, this is an opinion-based answer, probably not suited to SE.


2

By definition, a.out is a child process of time. So time is the parent pid of a.out! here's a test where I replace a.out with sleep 60: $ time sleep 50 & timepid=$! $ aoutpid=$(pgrep -P $timepid) $ ps -o ppid,pid,start,cmd w -p $$,$timepid,$aoutpid PPID PID STARTED CMD 2065 2068 21:34:57 -bash 2068 3297 22:16:05 -bash 3297 3298 22:16:05 sleep 50 ...



Only top voted, non community-wiki answers of a minimum length are eligible