This bash script searches for pdf files inside folders you declare in the first array (dir) and put those files in folders with the first 8 digits files’ names.
I use this script to sort pdf files created by Ricoh scanners. The files’ names are dates: 2015031312102345.pdf –> year-month-day-hour-minute-second and so on.
#!/bin/bash
a=/script/docks
b=/script/setramar
dir=( "$a" "$b" )
for i in ${dir[@]};
do
for lungo in $i/*.pdf;
do
#echo $lungo
nomefile=${lungo##*/}
#echo $nomefile
corto=${nomefile:0:8}
#echo $corto
if [ -d $i/$corto ];
then
cp $i/$nomefile $i/$corto
rm -f $i/$nomefile
else
mkdir $i/$corto
cp $i/$nomefile $i/$corto
rm -f $i/$nomefile
fi
done
done
One thought on “Sort pdf files with a bash script”