LDP/LDP/guide/docbook/abs-guide/ex57.sh

32 lines
1.1 KiB
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2004-01-26 00:03:37 +00:00
# badname.sh
2001-07-10 14:25:50 +00:00
# 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: + { ; " \ = ? ~ ( ) < > & * | $
2004-01-26 00:03:37 +00:00
#
rm $badname 2>/dev/null
# ^^^^^^^^^^^ Error messages deep-sixed.
2001-07-10 14:25:50 +00:00
done
# Now, take care of files containing all manner of whitespace.
find . -name "* *" -exec rm -f {} \;
2007-04-26 21:13:49 +00:00
# The path name of the file that _find_ finds replaces the "{}".
2001-07-10 14:25:50 +00:00
# The '\' ensures that the ';' is interpreted literally, as end of command.
exit 0
#---------------------------------------------------------------------
2007-04-26 21:13:49 +00:00
# Commands below this line will not execute because of _exit_ command.
2001-07-10 14:25:50 +00:00
# An alternative to the above script:
find . -name '*[+{;"\\=?~()<>&*|$ ]*' -maxdepth 0 \
2007-04-26 21:13:49 +00:00
-exec rm -f '{}' \;
# The "-maxdepth 0" option ensures that _find_ will not search
#+ subdirectories below $PWD.
2001-07-10 14:25:50 +00:00
# (Thanks, S.C.)