可能重複:
Extract filename and extension in bash
Linux: remove file extensions for multiple files如何刪除文件名的後綴特定的目錄,在linux
For example, A.txt B.txt, I want to rename then to A and B .
如何我shell腳本做呢?或者其他方法?謝謝。
可能重複:
Extract filename and extension in bash
Linux: remove file extensions for multiple files如何刪除文件名的後綴特定的目錄,在linux
For example, A.txt B.txt, I want to rename then to A and B .
如何我shell腳本做呢?或者其他方法?謝謝。
我會使用類似:
#!/bin/bash
for file in *.txt
do
echo "$file" "$(echo $file | sed -e 's/\.txt//')"
done
當然替換「.TXT」到任何文件擴展名要刪除,或兩個以上的引用,最好只使用$ 1(第一個傳遞給腳本的參數)。
Michael G.
for FILE in *.txt ; do mv -i "$FILE" "$(basename "$FILE" .txt)" ; done
它的工作原理。謝謝 !! – Clavier 2012-08-14 02:12:34
for i in *.txt; do mv "$i" "${i%.txt}"; done
'$(ls * .txt)'應該是'* .txt','$ file'應該被引用爲'「$ file」'(以及'「$(echo ...)」') ,正則表達式應該是''s/\。txt $ //''('g'標誌表示「做多個替換」,這不是你想要的,你只需要一個)。 – 2012-08-14 02:20:37
謝謝,我會更改代碼。 – mjgpy3 2012-08-14 02:24:14
更一般的方法.. – Clavier 2012-08-14 02:25:00