3

I have a set of image like that :

01-12_13:20:12_1366x768.png  01-12_13:20:46_1366x768.png  01-12_13:21:01_1366x768.png  01-12_13:21:06_1366x768.png
01-12_13:20:40_1366x768.png  01-12_13:20:47_1366x768.png  01-12_13:21:02_1366x768.png  01-12_13:21:07_1366x768.png
01-12_13:20:42_1366x768.png  01-12_13:20:49_1366x768.png  01-12_13:21:03_1366x768.png  01-12_13:21:08_1366x768.png
01-12_13:20:44_1366x768.png  01-12_13:20:59_1366x768.png  01-12_13:21:04_1366x768.png  01-12_13:21:10_1366x768.png
01-12_13:20:45_1366x768.png  01-12_13:21:00_1366x768.png  01-12_13:21:05_1366x768.png

I need to replace every : to _. How can I do that using bash commands ?

(note : i love when everything is compact and one-lined)

0

2 Answers 2

11

You can use a simple for loop, glob and parameter expansion to achieve this:

for f in *:*.png; do mv -- "$f" "${f//:/_}"; done
6

The for loop is one possible solution but i prefer rename.

rename "s/:/_/g" *

This tool renames multiple files according to the regex rule which is given.

14
  • i tried but didn't work for me Commented Jan 12, 2017 at 13:17
  • Whats the problem. Is there an error message? Commented Jan 12, 2017 at 13:18
  • 1
    I had to write rename : _ *.png, and my man rename doesn't seem to accept the syntax you provided, what distro are you using ? Commented Jan 12, 2017 at 13:25
  • 1
    sometimes under the name of prename. Commented Jan 12, 2017 at 14:33
  • 1
    There are several tools with the name rename. The one we are discussing here is written by Larry Wall, in the language perl. Commented Jan 12, 2017 at 15:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.