delete files names are or begin with dash “-“


bash:

# delete file named "-"
rm -- -
# delete files whose names begin with a dash
rm -- -*
# delete files whose names begin with a dash
find . -maxdepth 1 -name "-*" -delete

dash can be a bit tricky sometimes, because it leads program to think it is the beginning of an option. tells rm to treat everything after it as filenames. find can be a very good option for this task as well. Also note that I have used -maxdepth 1 to avoid find‘s default behaviour of searching for files recursively in sub directories.

, , , ,

  1. Leave a comment

Leave a comment