Выше есть много замечательных ответов. Я взял один из ответов выше и добавил к нему человеческий интерфейс. Может быть, кто-то найдет это полезным.
#!/bin/bash
pdf2Gray()
{
if [ -z "$1" ]; then
return 1
else
inputFile="$1"
fi
if [ ! -f "$inputFile" ]; then
echo "File not found"
echo "$inputFile"
return 2
fi
fileType="`file -b --mime-type \"$inputFile\"`"
if [ "$fileType" != 'application/pdf' ]; then
echo "This file is not a pdf"
echo "$inputFile"
return 3
fi
outFile="`basename -s.pdf \"$inputFile\"`-gray.pdf"
if [ -f "$outFile" ]; then
echo -en "File Exists, overwrite it? (Y/n) "
read overWrite
if [ -z "$overWrite" ]; then
overWrite="y"
fi
if [[ "$overWrite" != "y" && "$overWrite" != "Y" ]]; then
return 4
fi
fi
gs \
-q \
-sOutputFile="$outFile" \
-sDEVICE=pdfwrite \
-sColorConversionStrategy=Gray \
-dProcessColorModel=/DeviceGray \
-dCompatibilityLevel=1.4 \
-dNOPAUSE \
-dBATCH \
"$inputFile"
echo -en "\033[1;32m"
echo -n "$PWD/$outFile"
echo -e "\033[0m"
}
if [ -z $1 ]; then
echo "usage:"
echo "$0 file1.pdf file2.pdf file3.pdf..."
else
for file in "$@"
do
pdf2Gray "$file"
#echo $? #debug
done
fi
function imageext ()
{
if ! ((${#imageextensionlist[@]})); then
declare -ga imageextensionlist=($(grep / /etc/mime.types|grep 'image/'|xargs printf '%s\n'|grep -v /));
fi;
[[ " ${imageextensionlist[@]} " == *" ${1,,} "* ]]
}
function videoext ()
{
if ! ((${#videoextensionlist[@]})); then
declare -ga videoextensionlist=($(grep / /etc/mime.types|grep 'video/'|xargs printf '%s\n'|grep -v /));
fi;
[[ " ${videoextensionlist[@]} " == *" ${1,,} "* ]]
}
function imagesize () # you may need to install imagemagick
{
local re=$(identify -format %wx%h "${1}");
printf "${re%%x*}x${re##*x}"
}
cd /parrent/dir/where/your/pictures;
mkdir tmp;
mv * tmp/;
mkdir videos pictures other;
find "${PWD}/tmp" -type f | while read thefile;do
if imageext "${thefile##*.}";then
imgsize="$(imagesize "${thefile}")";
[[ ! -d "${imgsize:-none}" ]] && mkdir -p "${imgsize:-none}"
mv "${thefile}" pictures/${imgsize:-none}/;
elif videoext "${thefile##*.}";then
mv "${thefile}" videos/;
else
mv "${thefile}" other/
fi
done
это упорядочивает изображения по разрешению внутри изображений/ и помещает видео в видео/, а другие игнорируемые файлы внутри других/