I have a large directory of files last modified over the past several years through now. Is there an easy command or commands I can type one-time in an interactive bash shell that can create subdirectories with the name of each subdirectory being a four-digit year, and move respective files into each subdirectory when I cannot rely on any information in the file name regarding the age of the file, and finally verify everything I ran worked properly and I didn't lose any files or data?
For example given this completely fake example:
$ cd ~/Documents
$ ls -lhrt
...
-rw-r--r-- 4 user user 4.0K Jun 29 2017 oldfile.txt
-rw-r--r-- 4 user user 4.0K May 15 2018 2018file.md
-rw-r--r-- 4 user user 4.0K Apr 14 2019 04.dat
-rw-r--r-- 4 user user 4.0K Jul 21 2019 somepage.html
drw-r--r-- 4 user user 4.0K Jul 21 2019 somepage_files
-rw-r--r-- 4 user user 4.0K Mar 13 2020 march.dat
-rw-r--r-- 4 user user 4.0K Feb 12 18:03 file02.dat
-rw-r--r-- 4 user user 4.0K Oct 11 18:03 OctReport.txt
When I'm done, I want to end up with the following:
$ cd ~/Documents
$ find .
.
./2017
./2017/oldfile.txt
./2018
./2018/2018file.md
./2019
./2019/04.dat
./2019/somepage.html
./2019/somepage_files
./2019/somepage_files/...
./2020
./2020/march.dat
./2021
./2021/file02.dat
./2021/OctReport.txt