LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-20-2012, 03:08 AM   #1
kebertx
LQ Newbie
 
Registered: Jun 2012
Posts: 3

Rep: Reputation: Disabled
Want to make a bash script that removes a png file if a jpg has the same name.


And I don't know quite what to do

I want to find all .png images in a directory, and remove them if there exists in the same directory a .jpg which has the same filename (not including extension).

It seemed that this was the right place to learn the tricks I need. Any tips?
 
Old 06-20-2012, 03:46 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Code:
for file in *.jpg; do
    [[ -f "${file%.jpg}.png" ]] && rm "${file%.jpg}.png"
done
This is something you may be able to do interactively in the shell when your BASH skills improve a bit.

The expression "${file%.jpg}.png" changes the extension to .png using name expansion.

Last edited by jschiwal; 06-20-2012 at 03:47 AM.
 
Old 06-21-2012, 11:37 PM   #3
kebertx
LQ Newbie
 
Registered: Jun 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Yay thanks! My skills do need to improve, but the learning is the fun part anyways, so I don't mind that at all.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem-Simple bash script to copy the latest .jpg file RCCollins Linux - Software 6 11-24-2011 02:24 PM
Program to determine if a file is a valid image (jpg, png, gif, etc.) KDHofAvalon Linux - Software 7 06-09-2009 04:54 PM
BASH script that removes sub-directories (not just files) but keeps the two newest. kennc Linux - Newbie 2 04-23-2009 01:09 PM
jpg files has no preview in file tips, png does. Acidx Linux - Desktop 1 10-15-2006 01:52 PM
pnp to png or jpg illtbagu Linux - Newbie 1 01-26-2003 03:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration