2017年7月18日 星期二

[Linux 常見問題] How do I rename the extension for a batch of files?

Source From Here 
Question 
In a directory, I have a bunch of *.html files. I'd like to rename them all to *.txt by using the bash shell. 

How-To 
- test.sh 
  1. #!/bin/sh  
  2. for file in *.html; do  
  3.     new_ft=${file%*.html}  
  4.     echo "$new_ft"  
  5.     mv "$file" "${new_ft}.txt"  
  6. done  
Supplement 
How do I rename the extension for a batch of files? 
鳥哥 - 認識與學習 BASH: 變數內容的刪除、取代與替換 

沒有留言:

張貼留言

[ Python 常見問題 ] Get all object attributes in Python?

Source From  Here   Question   Is there a way to  get all attributes/methods/fields/etc. of an object in Python ?  vars()  is close to what ...