From 4fe9e9cf64b5c662ea730222eedf72a5972e5b7b Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 25 Nov 2021 13:20:13 +0100 Subject: [PATCH] bin: utilities for preparing backups --- .local/bin/scripts/cachetag | 5 +++++ .local/bin/scripts/latest | 3 +++ .local/bin/scripts/predate | 7 +++++-- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100755 .local/bin/scripts/cachetag create mode 100755 .local/bin/scripts/latest diff --git a/.local/bin/scripts/cachetag b/.local/bin/scripts/cachetag new file mode 100755 index 0000000..bfabcd5 --- /dev/null +++ b/.local/bin/scripts/cachetag @@ -0,0 +1,5 @@ +#!/bin/sh +echo 'Signature: 8a477f597d28d172789f06886806bc55 +# This file is a cache directory tag created by (application name). +# For information about cache directory tags, see: +# https://bford.info/cachedir/'>CACHEDIR.TAG diff --git a/.local/bin/scripts/latest b/.local/bin/scripts/latest new file mode 100755 index 0000000..70605f6 --- /dev/null +++ b/.local/bin/scripts/latest @@ -0,0 +1,3 @@ +#!/bin/sh -e +# Displays the latest files in the given directory or pwd +find "$1" -maxdepth 4 -type f -printf '%TF %f\n' | sort -r | head diff --git a/.local/bin/scripts/predate b/.local/bin/scripts/predate index 5a1ae75..7a3fa92 100755 --- a/.local/bin/scripts/predate +++ b/.local/bin/scripts/predate @@ -1,5 +1,8 @@ -#!/bin/sh +#!/bin/sh -e # Add the modification date in front of the filename +IFS='\n' for file -do mv --verbose --interactive "$file" "$(stat --format %y "$file" | cut -d' ' -f1)_$file" +do mv --verbose --interactive "$file" \ + "$(latest "$file" | head -2 | tail -1 | cut -d' ' -f1)_$(echo "$file" | sed 's/20\([0-9]\{2\}\)-\([0-9]\{2\}\)\(-[0-9]\{2\}\)\?_\?//')" done +# stat --format %y "$file" | cut -d' ' -f1