需求:需要大批量的移除文件夹中的某一类语言文件,希望能批量执行
"/Library/Application Support/Apple/BezelServices/AppleBluetoothHIDKeyboard.plugin/Contents/Resources/de.lproj"
couldn’t be removed,because you didn't authorize this operation."
/Library/Application Support/Apple/BezelServices/AppleBluetoothHIDMouse.plugin/Contents/Resources/de.lproj"
couldn’t be removed,because you didn't authorize this operation.
"/Library/Application Support/Apple/BezelServices/AppleBluetoothMultitouch.plugin/Contents/Resources/German.lproj" couldn’t be removed,because you didn't authorize this operation. "/Library/Application Support/Apple/BezelServices/AppleHSBluetooth.plugin/Contents/Resources/de.lproj" couldn’t be removed,because you didn't authorize this operation. "/Library/Application Support/Apple/BezelServices/AppleTopCaseHIDEventDriver.plugin/Contents/Resources/de.lproj" couldn’t be removed,because you didn't authorize this operation. "/Library/Application Support/Apple/BezelServices/IOAppleBluetoothHIDDriver.plugin/Contents/Resources/de.lproj" couldn’t be removed,because you didn't authorize this operation. "/Library/Application Support/Apple/BezelServices/IOBluetoothHIDDriverGeneric.plugin/Contents/Resources/de.lproj" couldn’t be removed,because you didn't authorize this operation.........
1)获取对应路径,过滤路径外的关键词句子
#!/bin/bash cat $1 |grep Library> localiation_path.txt #$1 表示运行脚本时,后面跟的文本 awk 'BEGIN {FS="\""}{print $2}' localiation_path.txt > localiation_final.txt
2)循环读取和删除对应的内容
#!/bin/bash num=0 cat $1|while read line #$1 表示运行脚本时,后面跟的文本 do rm -rf "$line" let num+=1 echo $num done
"$line" #需要用引号包含,才能解决路径中包含空格时不能执行命令的问题
读取过程的坑 # 被处理的文本中最后一行内容一定要包含换行符,否则有可能读出来少一行。
附:文本german.txt来源的语言搜索命令
#!/bin/bash sudo find /Library -name German.lproj > find_loc.txt sudo find /Library -name de.lproj >> find_loc.txt cat find_loc.txt |sort > find_final.txt原文链接:https://www.f2er.com/bash/391572.html