X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/blobdiff_plain/17d7b80328e653a7d65c4aac24c4f8173409c321..0d22dfcdb7eab1975d56ed36967885707470c828:/user/bkdatename?ds=sidebyside diff --git a/user/bkdatename b/user/bkdatename new file mode 100755 index 0000000..ace4e01 --- /dev/null +++ b/user/bkdatename @@ -0,0 +1,32 @@ +#!/bin/bash + +# Date: 2020-05-10T15:27Z +# Author: Steven Baltakatei Sandoval +# License: GPLv3+ +# Ref./Attrib: +# [1]: John1024 (2014-08-06). ["linux-shell: renaming files to creation time"](https://stackoverflow.com/a/25153352). Licensed CC BY-SA 4.0. +# [2]: Computer Hope (2019-05-04). ["Bash read builtin command"](https://www.computerhope.com/unix/bash/read.htm). + +# Description: Preappends modification time to all files in current +# working directory. + +# Usage: bkdatename + +# Prompt to change filenames for all files in working directory. +read -p "Append each file's modification date & time to the start of its name in the current working directory? (y/n)" -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]] # see [2] +then + #Perform renaming operation. + for f in * + do + FILE_NAME="$f" + FILE_MDATE="$(date -r "$f" +"%Y%m%dT%H%M%S")" # See [1]. + FILE_NAME_NEW="$FILE_MDATE".."$FILE_NAME" + # Display new file name + echo "Renaming $f to:""$FILE_NAME_NEW" + cp -p ./"$f" ./"$FILE_NAME_NEW" + rm ./"$f" + done + echo "Done." +fi