From 909ece30d234990d57526c444117f4d3f6ab3100 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Fri, 19 Apr 2019 14:44:14 -0400 Subject: [PATCH] Add functions: recent, recent_dirs, recent_files for finding most-recently modified file system objects. --- lib/login_functions.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/login_functions.sh b/lib/login_functions.sh index 307bec6..29bc3e2 100644 --- a/lib/login_functions.sh +++ b/lib/login_functions.sh @@ -15,6 +15,32 @@ tdu() { | cut -c 1-115 } +# Most-recently modified file system objects +recent() { + # Intentional non-quoting of the parameters, so that some can be ignored if + # not passed, rather than be passed to find as empty strings. + # NOTE that %T+ is a GNU extention. + find $@ -printf '%T@ %T+ %p\0' \ + | sort -z -k 1 -n -r \ + | head -n "$(stty size | awk 'NR == 1 {print $1 - 5}')" -z \ + | gawk -v RS='\0' ' + { + sub("^" $1 " +", "") # Remove epoch time + sub("+", " ") # Blank-out the default separator + sub("\\.[0-9]+", "") # Remove fractional seconds + print + }' + # gawk is able to split records on \0, while awk cannot. +} + +recent_dirs() { + recent "$1" -type d +} + +recent_files() { + recent "$1" -type f +} + pa_def_sink() { pactl info | awk '/^Default Sink:/ {print $3}' } -- 2.20.1