Answer the question
In order to leave comments, you need to log in
Bash script to sort files into folders by creation date?
Good day everyone!
I collected a file dump on xigmanas for myself and the question arose that I need a script that will sort photos from folder 1 into folder 2 by creation date, I used to use the provider's FTP and this script worked there:
#/bin/bash
SRC_DIR="/1"
DST_DIR="/2"
for F in ${SRC_DIR}/*; do
SUB=$(date -d"$(stat -c%y "${F}")" +%Y%m%d:%H)
mkdir -p "${DST_DIR}/${SUB}"
mv "${F}" "${DST_DIR}/${SUB}/"
done
Answer the question
In order to leave comments, you need to log in
So, you recently transferred all the files to the new server, and, accordingly, the creation date for all files is the same now?
FreeBSD uses a different version of stat, not all keys are the same as on most Linux.
Maybe you should just replace this
SUB=$(date -d"$(stat -c%y "${F}")" +%Y%m%d:%H)
with this
SUB=$(stat -f % Sm -t %Y%m%d-%H "${F}")
no freebsd at hand, nothing to check against
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question