L
L
lisenok4252019-01-10 14:20:01
bash
lisenok425, 2019-01-10 14:20:01

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

But on the new server, he stupidly transfers files to folder 2 without sorting. I myself am not strong in this matter, I will be very grateful for the help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2019-01-10
@lisenok425

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 question

Ask a Question

731 491 924 answers to any question