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)

ctrl-alt-delor
  • 27,473
  • 9
  • 58
  • 102
vdegenne
  • 1,676
  • 3
  • 16
  • 20

2 Answers2

11

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

for f in *:*.png; do mv -- "$f" "${f//:/_}"; done
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
nuviktor
  • 126
  • 2
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.