mirror of https://github.com/tLDP/LDP
32 lines
1.1 KiB
Bash
32 lines
1.1 KiB
Bash
#!/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 '*[+{;"\\=?~()<>&*|$ ]*' -maxdepth 0 \
|
|
-exec rm -f '{}' \;
|
|
# The "-maxdepth 0" option ensures that _find_ will not search
|
|
#+ subdirectories below $PWD.
|
|
|
|
# (Thanks, S.C.)
|