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?
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 -).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With