Hiya. I just have a quick question about something that I did that had an unexpected result.
Something ridiculous happened and hundreds of files erroneously got dropped in my Documents folder, so I went about deleting. At one point, I wanted to delete all the files that began with ‘l’ except for a few that began with ‘letter’, so I did this:
rm l^etter]*
Interestingly, that also left two files that started with ‘letalis’ that I’d wanted to delete. Obviously, there’s something I don’t know about shell expansion here. Why did it leave those two along with the ones I wanted left alone? How would I have made it where it would have deleted everything except those that started with ‘letter’?
By the way, I’m using BASH.
Thanks.
The construct ] denotes a character class, not a string as you imagine. What you were asking for was:
l, then any letter that is not (because of the ^, ! would also work) e, t, or r (duplicates are ignored), then anything.
Since the second letter of letalis is e, this did not match so was left out of the expansion.
Oh geez. I actually thought I knew that. I think I need more sleep.
So what would have accomplished what I was trying to accomplish?
And thank you very much, by the way. That was a serious brain fart on my part.
Either using a pipe to filter out filenames that match letter* or using the extended pattern matching operator !(pattern-list) described in the man page which I have never tried.
Sometimes it’s faster to reduce the namespace in an ad hoc way:
rm l!e]*
and then deal with the few stragglers that begin with le but not letter.
Thank you. It’s the extended pattern matching that I was looking for.