-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
  • 791
  • 3
  • 11
  • 20
  • 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
SriniV
  • 10,691
  • 14
  • 59
  • 88
0

Another way is:

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

Alternatively if you have perl version of the rename utility:

rename 's/^0/M0/' *
Arkadiusz Drabczyk
  • 10,250
  • 2
  • 20
  • 35