how to delete filename's specific suffix in a dir, in linux

Possible Duplicate:
Extract filename and extension in bash
Linux: remove file extensions for multiple files

For example, A.txt B.txt, I want to rename then to A and B . 

How can I do it with shell script? Or other method ? Thanks.


I would use something like:

#!/bin/bash

for file in *.txt
do
    echo "$file" "$( echo $file | sed -e 's/.txt//' )"
done

Of course replace the two above references of ".txt" to whatever file extension you are removing, or, preferably just use $1 (the first passed argument to the script).

Michael G.


for i in *.txt; do mv "$i" "${i%.txt}"; done

for FILE in *.txt ; do mv -i "$FILE" "$(basename "$FILE" .txt)" ; done
链接地址: http://www.djcxy.com/p/57088.html

上一篇: 与grep匹配的模式

下一篇: 如何在linux中删除dir中文件名的特定后缀