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 ...


13

There are DST-free timezone definitions provided which just define the GMT-offset, called Etc/GMT±X: $ date Mon Apr 7 11:08:56 CEST 2014 $ TZ=Etc/GMT-1 date Mon Apr 7 10:09:16 GMT-1 2014 $ Just link/copy the one you need to /etc/localtime and you should be fine and DST-free: $ ln -s /usr/share/zoneinfo/Etc/GMT-1 /etc/localtime Edit: For non-integer ...


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.


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

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


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

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

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

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

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

In ksh, bash and zsh, time is a keyword, not a builtin. Redirections on the same line apply only to the command being timed, not to the output of time itself. $ time ls -d / /nofile >/dev/null 2>/dev/null real 0m0.003s user 0m0.000s sys 0m0.000s To redirect the output from time itself in these shells, you need to use an additional level ...


4

For a running process you can do this: PID=5462 command ps -p "$PID" -o etime command ps -p "$PID" --no-headers -o etime As a general feature you can modify your shell prompt. This is my bash prompt definition: TERM_RED_START=$'\033[1m\033[31m' TERM_RED_END=$'\033(B\033[m' PS1='\nec:$(ec=$?; if [ 0 -eq $ec ]; then printf %-3d $ec; else echo -n ...


4

Call time myprogram. This reports wall clock time, user time and system time. User time is the time spent by the process in computations. If the program is multithreaded and the machine has multiple processors, the time spent on all processors is summed (so for a sufficiently parallel program, the user time can be more than the wall clock time). The system ...


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 ...


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

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

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

If you can get the pid, which shouldn't be hard with either ps, /proc/self or $! depending on whether or not you background it you can find this in: /proc/$pid/stat: utime %lu (14) Amount of time that this process has been scheduled in user mode, measured in clock ticks (divide by ...


3

With ntpdate: ntpdate -d 0.debian.pool.ntp.org Or for the offset only: ntpdate -d 0.debian.pool.ntp.org | sed -n '$s/.*offset //p'


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

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 ...


2

If you mean a shell variable: t=7,51,10,22,3,2014 perl -MTime::Local -le 'print timelocal split ",", shift' -- "$t" t=1398163867 perl -le 'print scalar localtime shift' -- "$t"


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

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

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

#!/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.



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