Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想将 100 个 .txt 文件更改为 .log 文件。我有以下过程,但它不起作用。
ls |grep *.txt |while read a ; do b = 'echo $a |cut d"." -$f1'; c=$b ; mv $a $c; done
提前致谢 !!
for i in *.txt; do mv $i $(basename -s '.txt' $i).log; done
或者,更简单的是,如果您的系统具有以下rename命令:
rename
rename 's/\.txt$/.log/' *.txt
for i in *.txt do mv $i ${i%.*}.log done
${var%"pattern"} 取变量的内容从开始直到最后一个模式对应(从结束)(排除)。因此,“.*”在这种情况下剪切了 .txt。