On 9/22/15 1:52 PM, Bastian Bittorf wrote: > +maxtime() { > + local dir file > + > + find /etc -type d | while read dir; do > + file="$dir/$( ls -1t "$dir" | head -n1 )" > + [ -e "$file" -a "$file" != '/etc/dnsmasq.time' ] && date -r > "$file" +%s > + done | sort -nr | head -n1 > +} It appears that if /etc/dnsmasq.time is the newest file in /etc, it will "shadow" the next-newest file. "ls -lt /etc | head -n1" will be /etc/dnsmasq.time, and no other /etc/* files will be checked. The new code will also check the mod time of directories and symlinks, unlike the previous implementation.
I was experimenting a little. The fastest is probably "ls -t $(find /etc -type f) | head -1", but that does not behave well if there are too many files in /etc (too many args). Using xargs to split the ls invocations is possible, but then each xargs invocation needs to take the max separately. The fourth sample below does this. "test" has: test $a -ot $b ($a older than $b). This makes the script reasonably straightforward (only checks files, ignores arbitrary paths) and pretty fast in my test: local file newest for file in $( find /etc -type f ! -path /etc/dnsmasq.time ) ; do [ -z "$newest" -o "$newest" -ot "$file"] && newest=$file done echo $newest # time sh -c 'find /etc -type f -exec date -r {} +%s \; | sort -nr | head -n1' 1443239314 real 0m 0.77s user 0m 0.17s sys 0m 0.58s # time sh -c 'date -r $(ls -t $( find /etc -type f ) | head -1) +%s' # fails if /etc contains too many files 1443239314 real 0m 0.04s user 0m 0.02s sys 0m 0.03s # time sh -c 'local file newest; for file in $(find /etc -type f ! -path /etc/dnsmasq.time) ; do [ -z "$newest" -o "$newest" -ot "$file" ] && newest=$file ; done ; [ "$newest" ] && date -r "$newest" +%s' 1443239314 real 0m 0.06s user 0m 0.03s sys 0m 0.03s # time sh -c 'find /etc -type f ! -path /etc/dnsmasq.time | xargs sh -c '\''ls -t "$@" | head -1'\'' - | while read p ; do date -r $p +%s ; done | sort -nr | head -1' 1443239314 real 0m 0.07s user 0m 0.02s sys 0m 0.06s Feel free to use or ignore. -- -Justin justinval...@gmail.com
smime.p7s
Description: S/MIME Cryptographic Signature
_______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel