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: 變數內容的刪除、取代與替換 

沒有留言:

張貼留言

[Linux 常見問題] What's the best way to send a signal to all members of a process group?

Source From  Here   Question   I want to  kill a whole process tree.  What is the best way to do this using any common scripting languages? ...