Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've been reading a lot of tutorials but cant find exactly what I want.
I want to check if there are any JPG or jpeg files before I process them with ImageMagik.
All I have found is
if [ -f filename ]
which only checks for one file, I want to check for *.JPG but using if [ -f *.JPG ] fails if more than one JPG file exists.
Keefaz big thanks, that script for identify worked well and after changing $h > 800 to $w >= $h I got rid of the portrait orientated pics as well as the small ones. It takes 10 - 15 minutes to process approx 12500 files and I can live with that especially as my box is about 7 years old.
Oops I haven't explained my problem properly. I want to make all JPG and jpeg files jpg files. At the moment I do "rename JPG jpg *.JPG" (same for jpeg) and ignore the error message when there are no files to be changed. I would much prefer to have the rename in some sort of test.
Second question is to do with tidying up the file names. The script I found uses tr so I have ended up with this bit of code
image3=`echo "$image2" | tr " " "_"`
if [ "$image3" != "$image1" ]; then
mv "$image1" "$image3"
fi
But I really would like to be able to do the test first. Anyone got any alternatives ?
Looks like your sed knowledge is better than my typing ability (image2 should read image1). Still have the issue of doing the test after the change, which I was taught is bad programming.
If it helps you with sed while searching script tutorials I came across this
# badname.sh
# Delete filenames in current directory containing bad characters.
for filename in *
do
badname=`echo "$filename" | sed -n /[\+\{\;\"\\\=\?~\(\)\<\>\&\*\|\$]/p`
# badname=`echo "$filename" | sed -n '/[+{;"\=?~()<>&*|$]/p'` also works.
# Deletes files containing these nasties: + { ; " \ = ? ~ ( ) < > & * | $
#
echo "rm " "$badname"
# rm $badname 2>/dev/null
# ^^^^^^^^^^^ Error messages deep-sixed.
done
but that doesn't solve the issue of I would rather do the test for spaces (and/or other dodgy characters) before changing the file name.
Test for spaces doesn't matter as long as you just manipulate the file name
After you finish the name change, you just test with -f if file exists before doing the actual rename
PS: thanks for the sed examples, have to dig it a little more
I could get silly and say :- but, but, but, even COBOL lets you say
IF filename INCLUDES a space THEN PERFORM the change
However I know shell scripting is not compiled and therefore is limited in what can be done.
Would it be possible to write a bash function along the lines of
Function Includes(filename)
local respone = false
move filename to an array of single characters the length of filename # this line is the tricky bit
for cnt = 1 , length of filename
do
if array[cnt] = " "
then
response = true
fi
od
return response
I can see issues with the above code already, such as it probably should return true
as soon as it finds a space. More importantly if I was to write that then it would seem
sensible to change the space characters there and return the new file name and then I wouldn't
need the line with tr in it.
The script is getting better, processed about 30000 files in 16 minutes yesterday.
I like the idea of GLOBIGNORE.
So will have to do some more testing today.
I'm getting really really bored with two things, one - spending what seems like hours going through tutorials and not finding what I need, two Hello World !
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.