簡體   English   中英

遞歸重命名時如何將output到原目錄?

[英]How to output to the original directory when renaming recursively?

目錄示例:


./lv1/lvN/*.json

./lv1/*.json

demo.sh


這是我的腳本:


# ...

# Get all paths recursively

# exclude dir

find . -name *.json > json_list

# Read line by line, rename and output to the original directory

while read -r line_content; do

    mv "${line_content}" ${RANDOM}.json # How do I export to the original directory?

done < json_list

# ...


如何導出到原始目錄?

嘗試 IFS 或 AWK 將路徑拆分為兩個字段,但有更好的方法嗎?

我想你可能正在尋找

mv "${line_content}" "${line_content%/*}/${RANDOM}.json"

有關${line_content%/*}的解釋,請參閱刪除字符串的一部分(BashFAQ/100(How do I do string manipulation in bash?))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM