LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-02-2014, 06:35 PM   #1
ilovepoker
LQ Newbie
 
Registered: Sep 2014
Posts: 1

Rep: Reputation: Disabled
Debian Bash Script Help Please...


Ok i need some help here people...
I have 30k+ images without extensions...
I used a program called GPRename to give each of my images a random name, because some of the names were very long so they were causing problems, and it deleted the file extension on all my pictures now I'm having difficulty opening the images on my windows computer and my phone (no prob on linux)
I was wondering if any of you know of a program/script I can use that would add the correct file extension to the end of all the images
I was thinking of a script using the bash command "file" but i'm not very good with bash so I would have no idea how to do this for multiple files
 
Old 10-02-2014, 07:30 PM   #2
Philip Lacroix
Member
 
Registered: Jun 2012
Distribution: Slackware{,-current}, OpenBSD
Posts: 373

Rep: Reputation: 419Reputation: 419Reputation: 419Reputation: 419Reputation: 419
This will rename all images recursively by adding the extension extracted from the output of the file command (in the "cut" part I assumed that file names don't have spaces in them):

Code:
IM_PATH="path_to_images"

for image in $IM_PATH/* ; do
  ext=$(file "${image}" | cut -d ' ' -f 2)
  mv "${image}" "${image}.${ext}"
done

Last edited by Philip Lacroix; 10-02-2014 at 07:43 PM. Reason: assumption more explicit
 
  


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
Bash script to update Debian type systems, a couple of questions k3lt01 Programming 24 11-15-2011 08:10 PM
Invoking java from a bash terminal via shell script fails under Mint Debian rizwanjavaid Programming 3 02-16-2011 01:36 PM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
[SOLVED] bash script (qmail) won't boot but starts from console (debian lenny) dbj Linux - Server 9 11-21-2009 07:03 AM
writing a bash/ perl script on debian phr00ta Programming 4 01-29-2004 01:38 PM


All times are GMT -5. The time now is 04:29 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration