Bash rename

This is one more for myself than anyone else as I keep forgetting how todo it…. but if anyone is interested. I normally don’t use bash – I’m not entirely sure why I don’t (if you don’t know what bash is, then I wouldn’t worry – its the Bourne Again Shell and is based on the Bourne shell, sh, the original command interpreter). Anyway, this is a very simple thing todo.. but every time I come todo it I have to look it up, so I’m going to just look it up here…
Just to add some text at the front:

for i in *; do mv “$i” “photo${i}.jpg” ; done

To remove some text in the string:

for i in *.jpg; do mv “$i” “${i/Yourself}” ; done

and to rename as a numeric string… my most common task…

number=0
for i in *.jpg; do mv “$i” “$number” ; (( number += 1 )); done

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: