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