Reputation: 51
I am trying to remove files in a directory using rm
and without deleting the directory itself in a script. The examples I see only do this while in the directory itself, and I would like to do it without navigating there.
I tried
rm "$(dirname $1)/filetokeep/*"
but it is not working. Any help?
Upvotes: 5
Views: 207
Reputation: 798526
Quoting the wildcard inhibits expansion.
rm -- "$(dirname -- "$1")/filetokeep"/*
Using --
ensures that values can't be interpreted as optional arguments rather than positional ones (so that things still work if the directory named in $1
starts with a -
).
Upvotes: 6