如果存在类似的文件路径:
<configuration>
<!-- Only administrators may access AdminTools.aspx -->
<location path="AdminTools.aspx">
<system.web>
<authorization>
<allow roles="Administrators" />
<deny users="*" />
</authorization>
</system.web>
</location>
</configuration>
bash中有没有办法重命名文件,包括文件所在的父目录和祖父目录的名称?
例如
/path/topic/day/name.pdf
感谢您的帮助
答案 0 :(得分:0)
#!/bin/bash
function assemble_path() {
echo "$(realpath "$1" | rev | cut -d'/' -f2- | rev)"
}
function assemble_parents() {
echo "$(echo "$1" | rev | cut -d"/" -f-2 | rev | tr '/' '-')"
}
function rename_to_parents() {
filetype=$(echo "$1" | rev | cut -d"." -f1 | rev)
filepath=$(assemble_path "$1")
parents=$(assemble_parents "$filepath")
mv "$(realpath "$1")" "$filepath/$parents.$filetype"
}
rename_to_parents "$1"
用法:
rename.sh
chmod u+x rename.sh
./rename.sh name.pdf
输出(/path/topic/day/name.pdf
):
/path/topic/day/topic-day.pdf