Bash – for loop

May 12, 2013
linux bash programming

Say you have some PHP files and you need to replace the .php extension with .html. The “for” loop in bash comes handy to do this task. However, prior to renaming we need to strip the .php extension from the file name and here awk does a great job. See a on-liner action :

for file in `ls | awk -F"." {'print $1'}`;do mv $file.php $file.html;done

I remember a colleague once asked me something similar and I used the “for” loop to add the .html extension. That time I didn’t strip the previous extension and the file names ended as .php.html which doesn’t look quite nice.

City Council of Barcelona switches from Microsoft Windows to Linux

February 11, 2018
linux ubuntu microsoft open source data protection

linux.com website compromised?

December 7, 2017
linux wordpress security

Linux Magazine's special edition on openSUSE

November 20, 2017
opensuse linux university-of-mauritius education