Archive

Posts Tagged ‘Bash’

Rename files via shell-script

October 28th, 2009

In order to a miss configuration I had for a long time the problem with hundreds of
files which had a crap name. Tonight I had the time to solve this:

Preamble:

-rw------- 1 apache root 273K 24. Jul 15:37 UPLOAD_PATH1
-rw-r--r-- 1 apache root 275K 24. Jul 15:37 UPLOAD_PATH10
-rw-r--r-- 1 apache root 220K 19. Okt 15:14 UPLOAD_PATH11
-rw-r--r-- 1 apache root 3,1M 19. Okt 15:17 UPLOAD_PATH12
-rw-r--r-- 1 apache root 241K 19. Okt 16:13 UPLOAD_PATH13
-rw------- 1 apache root  60K 24. Jul 15:37 UPLOAD_PATH2
-rw------- 1 apache root 105K 24. Jul 15:37 UPLOAD_PATH3
-rw------- 1 apache root  60K 24. Jul 15:37 UPLOAD_PATH4
-rw------- 1 apache root  60K 24. Jul 15:37 UPLOAD_PATH5
-rw------- 1 apache root  60K 24. Jul 15:37 UPLOAD_PATH6
-rw------- 1 apache root  60K 24. Jul 15:37 UPLOAD_PATH7
-rw------- 1 apache root  60K 24. Jul 15:37 UPLOAD_PATH8
-rw-r--r-- 1 apache root 273K 24. Jul 15:37 UPLOAD_PATH9

The way to rename them is pretty simple with a bash script, but the notation/ syntax
is just a little bit tricky.
While searching with google, I’d found several scripts but no simple solution.
My solution just executes a ls command, push the output in an array, and the builds a new name using sed.
After this steps, the new name is ready to use with a simple mv command.

Solution via bash:

#!/bin/bash
list=(`ls `)
for filename in "${list[@]}"
do
  myvar=$(echo $filename | sed 's/UPLOAD_PATH//g')
  #echo 'mv '$filename' '$myvar
  mv $filename $myvar
done

Linux , ,

Rename photos by EXIF Timestamp, Date

September 26th, 2009

Something beside the usually blog entries…

After the my last surf holidays in September 2009 I had a problem with my two cameras… Sony Alpha 200 and Pentax Option W60. Both got different filenamings and right now I’ve never seen a camera where you can fully design the filename format.
While I worked with windows, years ago, I used a app named ‘Joe’,.. but port a windows app to Linux.. no thanks ;)
The name of (one) solution is exiv2!

Installing exiv2 on debian based systems:

sudo apt-get update
apt-get install exiv2

Renaming:
Launch a terminal, go to the dir where the photos are located

cd /home/per/Documents/Portugal2009

Rename them:

exiv2 mv -r "%Y-%m-%d_%H:%M:%S_My_Name" *

Before: IMGP0078.JPG
After: 2009-09-03_16:54:42_My_Name.JPG

Linux, Photo , , ,