Can someone suggest on how to rename the file name:
head.body.date.txt
To:
head_body_date.txt
Is there a single line statement to do the rename in Unix?
command linemvrename
Can someone suggest on how to rename the file name:
head.body.date.txt
To:
head_body_date.txt
Is there a single line statement to do the rename in Unix?
Best Answer
Iterate over the filenames, and use Parameter expansion for conversion:
The parameter expansion pattern,
${f//./_}
replaces all.
s with_
s in the filename ($f
).The above will do a dry-run, to let the actual renaming take place, remove
echo
:If you want to deal with any extension, not just
.txt
:After checking remove
echo
for actual action:Generic, for arbitrary number of dots, at least one: