putInDir is a bash script to move a file in a directory which has its name or, putInDirDate (see below), its date.
These two should be brought together ultimately (with options).
Call the script with the file to move as argument:
putInDir filename.dat
It will create a directory "filename" and move "filename.dat" in it.
To process all files of a given extension, use:
for f in *.zip; do putInDir "$f" ; done
# _ ___ ____ _
# _ __ _ _| |_|_ _|_ __ | _ \(_)_ __
# | '_ \| | | | __|| || '_ \| | | | | '__|
# | |_) | |_| | |_ | || | | | |_| | | |
# | .__/ \__,_|\__|___|_| |_|____/|_|_|
# |_|
#
# F.P. Laussy -- laussy.org
# Wed Apr 25 10:00:49 CEST 2012
# v°0.1
#
# This create a directory with the name of the file
# passed as an argument and move the file inside.
# Separating filename from extension
filename=$(basename $1)
extension=${filename##*.}
filename=${filename%.*}
# Create directory and translate the file
mkdir $filename
mv $1 $filename</code>
Copy the file in the directory where files to be sorted are present (check extension in the script) and run. Be careful, it could be dangerous (no undo!)
#!/bin/bash
#23 September 2017
for x in *.JPG; do
d=$(date -r "$x" +%Y-%m-%d)
mkdir -p "$d"
mv -- "$x" "$d/"
done