ex57.sh
来自「一本完整的描述Unix Shell 编程的工具书的所有范例」· Shell 代码 · 共 28 行
SH
28 行
#!/bin/bash# badname.sh# Delete filenames in current directory containing bad characters.for filename in *do badname=`echo "$filename" | sed -n /[\+\{\;\"\\\=\?~\(\)\<\>\&\*\|\$]/p`# badname=`echo "$filename" | sed -n '/[+{;"\=?~()<>&*|$]/p'` also works.# Deletes files containing these nasties: + { ; " \ = ? ~ ( ) < > & * | $# rm $badname 2>/dev/null# ^^^^^^^^^^^ Error messages deep-sixed.done# Now, take care of files containing all manner of whitespace.find . -name "* *" -exec rm -f {} \;# The path name of the file that "find" finds replaces the "{}".# The '\' ensures that the ';' is interpreted literally, as end of command.exit 0#---------------------------------------------------------------------# Commands below this line will not execute because of "exit" command.# An alternative to the above script:find . -name '*[+{;"\\=?~()<>&*|$ ]*' -exec rm -f '{}' \;# (Thanks, S.C.)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?