![](/img/trans.png)
[英]How to replace backup file with timestamp in its name without producing duplicates in Linux Bash (shell script)
[英]Replace the name of a file (without extension) for dir name in bash linux
我在一个目录中有多个文件。 这些文件的名称为“Output”(Output.txt、Output.csv、Output.tsv 等),我想将该名称替换为目录名称。 我尝试了几种方法,但只能用扩展名替换文件名。 以下方法无效:
nombre=${PWD##*/}
for f in Output*; do
mv -- "${file%. *}" "$nombre"
done
$ ls test/
Output.csv Output.tsv Output.txt
$ rename -n 's!\./(.*?)/.*(\.\w+)!./$1/$1$2!' ./test/Output.*
rename(./test/Output.csv, ./test/test.csv)
rename(./test/Output.tsv, ./test/test.tsv)
rename(./test/Output.txt, ./test/test.txt)
当 output 看起来令人满意时,删除-n
(又名dry-run
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.