[英]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.