-1

I have a folder with many files named as '00001.sdf', '00002.sdf' and so on. I want to add an 'M' character at the beginning of each file name, like this 'M00001.sdf', 'M00002.sdf. How can I do this using a bash command?

Marcos Santana
  • 911
  • 5
  • 12
  • 21
  • 1
    I copy pasted the title of your question in google and [Rename all files in directory from $filename_h to $filename_half?](http://stackoverflow.com/questions/7450818/rename-all-files-in-directory-from-filename-h-to-filename-half) was the first result. – f3xy May 04 '17 at 14:42

3 Answers3

0

Here is one way

for f in * ; do mv "$f" "M$f" ; done
Srini V
  • 11,045
  • 14
  • 66
  • 89
0

Another way is:

ls -1 *.sdf | awk '{ system("mv "$0" M"$0) }'
Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18
0

Alternatively if you have perl version of the rename utility:

rename 's/^0/M0/' *
Arkadiusz Drabczyk
  • 11,227
  • 2
  • 25
  • 38