In Linux, how do I delete all files in a directory that do NOT start with a pref (for example sess_*)?
|
feedback
|
|
I prefer find:
You might want to adjust depth in order to avoid recursion. | |||
|
feedback
|
|
In the above cd /tmp ; ls -1 | grep -v sess_ | xargs rm -f the grep should be grep -v '^sess_*' Other wise files such as ppp_sess_333 would be left behind. | |||
|
feedback
|
|
One solution is to pipe it through grep. For example:
Another option is find (this excludes directories too):
| |||||||||
feedback
|