bash - Write command that outputs all JPG images in directory with specific word in file name -
how write command outputs of jpeg images in directory contain word “red” file named “red_photos.txt”.
generating files containing red easy; can pattern *red*
. tricky part finding out whether jpeg file or not. like
for f in *red* if file $f | fgrep -q ' jpeg ' echo $f >>red_photos.txt fi done
two issues improvement left exercise (because not directly related question):
if there many files containing red, might "arg list long" error.
if there no file containing red, might error message saying wildcard not match files (depending on settings in bash scripts).
Comments
Post a Comment