-
Notifications
You must be signed in to change notification settings - Fork 8
/
rename-by-date.sh
41 lines (28 loc) · 1.03 KB
/
rename-by-date.sh
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
#!/bin/bash
# Copyright (c) 2020, lowkey digital studio
# Author: Nathan Wolek
# Usage of this file and its contents is governed by the MIT License
# BEGUN - 23 April 2020
# GOAL - change the WAV filename to be based on the birthdate
# Example of desired format - 20200406_040000
# expected input .WAV files (upper case extension) produced by the AudioMoth
# expected output .wav files (lower case extension)
# make directory for output
if [ ! -d output ]; then
mkdir -p output
fi
# iterate through all arguments
for file in $@
do
# Use 'stat' to get the birthdate of the file, but switch the format
# Example of default format from stat - Apr 6 04:00:00 2020
# Example of desired format - 20200406_040000
format='%Y%m%d_%H%M%S'
birthdate=$(stat -f "%SB" -t $format $file)
# copy the original sound file and give it a new birthdate name
cp $file output/$birthdate.wav
# apply old attributes to the new file
touch -r $file output/$birthdate.wav
# touch one more time to update the modification date
touch output/$birthdate.wav
done