I am writing a bash script to move all images into a central file.
I create the list of image files with:
img_fil='/home/files/img_dump.txt'
locate -i image | grep \.jpg > "$img_fil"
locate -i image | grep \.jpeg >> "$img_fil"
locate -i image | grep \.gif >> "$img_fil"
locate -i image | grep \.tif >> "$img_fil"
locate -i image | grep \.png >> "$img_fil"
But when I start processing the dump file for this, most of the paths contain blanks so this does not work:
while read -r fline
do
if [ ! -e "$fline" ]; then
echo "F=> $fline"
mv "$fline" "$img_dir"
else
fpath="$(dirname $fline)"
fname="$(basename $fline)"
echo "F=> $fname P=> $fpath"
fi
done
The dirname and basename always parse at the blanks so will not process right.
How do I get this to work?
locate -0 \.jpg \.jpeg | xargs -0 ...
might help here. Also,find ~ ...
might be more accurate. – nohillside Feb 25 '18 at 21:24fpath=$(dirname "$fline")
andfname=$(basename "$fline")
– jesse_b Feb 25 '18 at 21:25