Regular Expressions 101

Community Patterns

Prevent simple rm rf cp mv from breaking system or top level home directories

0

Regular Expression
PCRE (PHP <7.3)

`
^(?:rm -r?f?|(?:cp|mv))\b.*?\s/((?:etc|boot|dev|lib(?:64)?|misc|mnt|net|opt|root|sbin|srv|sys|usr|var|bin)(\s|$|/)|home(\s|$|[/]+(?![^/]+[/+])))
`
g

Description

Prevent acidental deletion of important system files and user directories.

Submitted by anonymous - 7 years ago