![](/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.