-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdifftime.1
More file actions
123 lines (111 loc) · 2.81 KB
/
difftime.1
File metadata and controls
123 lines (111 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
.TH DIFFTIME 1 2020-11-17 GNU "User Commands"
.SH NAME
difftime \- display delta time from two files or one file and now
.SH SYNOPSIS
.B difftime
[\fI\,OPTION\/\fR]... \fI\,FILE\/\fR [[\fI\,OPTION\/\fR] \fI\,FILE\/\fR]
.SH DESCRIPTION
difftime is a simple utility to calculate and print out the delta time from
two files or a file and now. It's usefull to make a gate in a script, based on time.
The output is always a number. It can be signed with a '-' before the digits.
By default there isn't a new line character.
The first argument must be a file. With no second argument, it prints out the
time differnce between the last modification time of the file and now.
The output is in seconds by default.
Passing the second argument, the difference is between the modification time of
the second and the first. See OPTIONS to change this behaviour.
.SH OPTIONS
.TP
\fB\-a\fR, \fB\-\-atime\fR \fI\,FILE\/\fR
compare last access time
.TP
\fB\-c\fR, \fB\-\-ctime\fR \fI\,FILE\/\fR
compare change time
.TP
\fB\-m\fR, \fB\-\-mtime\fR \fI\,FILE\/\fR
compare modification time
.TP
\fB\-f\fR, \fB\-\-field\fR \fI\,field\/\fR
diff only a part of the timestamp. 'Y' year, 'M' month, 'D' day, 'h' hour, 'm' minute, 's' second.
.TP
\fB\-A\fR, \fB\-\-absolute\fR
output without sign
.TP
\fB\-D\fR, \fB\-\-days\fR
output in days
.TP
\fB\-H\fR, \fB\-\-hours\fR
output in hours
.TP
\fB\-M\fR, \fB\-\-minutes\fR
output in minutes
.TP
\fB\-P\fR, \fB\-\-print\fR
add newline character after the number
.TP
\fB\-h\fR, \fB\-\-help\fR
display this help message
.TP
\fB\-v\fR, \fB\-\-version\fR
display the software version
.SH "EXIT STATUS"
With no arguments, it fail with exit code not zero.
If the file doesn't exists it fail with exit code not zero.
.SH BUGS
Bugs can be reported at
https://github.com/ognibit/difftime/issues
.SH EXAMPLES
Show how old is a file (from now) in minutes
.
.IP
.EX
difftime -A -P -M /var/spool/myspool
.EE
.
.P
Show time difference from files in days
.
.IP
.EX
difftime -P -D /var/spool/myspool myfile
.EE
.
.P
Show the time difference in seconds between the access time of one file and the
change time of the other
.
.IP
.EX
difftime -P -A -a /var/spool/base -c /var/spool/gate
.EE
.
.P
A simple way to use difftime into a script to do some operation only after 10
seconds to the previous effective execution.
.
.IP
.EX
#!/bin/bash
SPOOL_FILE="spool"
# time in seconds
TIME_GATE=10
DT=$(./difftime -A $SPOOL_FILE 2> /dev/null ) || DT=$TIME_GATE
[ $DT -lt $TIME_GATE ] && exit 1
echo "Do the stuff"
# reset the spool time
touch $SPOOL_FILE
.EE
.
.P
Execute a command once a day (like anacron)
.
.IP
.EX
DT=$(./difftime -A -f D $SPOOL_FILE 2> /dev/null ) || DT=1
[ $DT -eq 0 ] && exit 1
.EE
.SH AUTHORS
Omar Rampado <https://github.com/ognibit>
.SH "SEE ALSO"
stat(1)
difftime(3)