1

I have multiple folders and each one have around 175 files in it. file names are like

1.wav
2.wav
3.wav
......
175.wav 

I have to rename them as

A1.wav
A2.wav
A3.wav
......
A175.wav 

In other words I have to append Letters in previous file names.

I am wondering if there is a easy way to do this.

Ubuntu Version is 16.10

Adnan Ali
  • 219
  • 1
  • 3
  • 12

3 Answers3

3

User prename command:

$ prename -nv 's/^(.*)$/A$1/' *.wav                    
1.wav renamed as A1.wav
2.wav renamed as A2.wav
3.wav renamed as A3.wav

The way this reads is simple:

  • *.wav allows the shell to expand the wild card to list of all files that end with .wav. When the shell runs the full command, the computer will see prename -nv 's/^(.*)$/A$1/' 1.wav 2.wav 3.wav and so on as the actual command.
  • The 's/^(.*)$/A$1/' is actually is s/PATTERN/REPLACEMENT regular expression with grouping (.*), which allows us to group the whole name of the file from beginning ^ to end $ and refer to it as $1.

Note that -nv switches are for verbose -v and dry-run -n. If you're happy with the test run, remove -n to apply actual renaming.

3

There are many ways, my own choice would be a 'for' loop:

for f in *.wav ; do mv "$f" "A$f" ; done

This is simple and easily modified for other needs...

andrew.46
  • 39,359
2

Using rename:

rename 's/([0-9]+).wav/A\1.wav/' *.wav
  • s/SEARCH-FOR/REPLACE-WITH/ within-this-files
  • ([0-9]+) holds the number section then we can use it again using \1.
  • A\1.wav: A + (numberic section) + .wav
Ravexina
  • 57,256