With a little side of applesauce...

Wednesday, March 12, 2008

Regex fun

Here are some reminders for for loops, deleting various types of file patterns:

files which contain ".":
for f in $(ls | grep "^.*\..*$"); do sudo rm -Rf $f ; done

files which start with a number:
for f in $(ls | grep "^[0-9].*$") ; do sudo rm -Rf $f ; done

files which contain a number:
for f in $(ls | grep "^.*[0-9].*$") ; do sudo rm -Rf $f ; done

files which contain "{":
for f in $(ls | grep {); do sudo rm -rf $f ; done

files which contain "-"
for f in $(ls | grep -) ; do sudo rm -rf $f ; done

files which start with "u":
for f in $(ls | grep ^u.* | grep -v ushers); do sudo rm -rf $f ; done

for f in $(ls | grep _) ; do sudo rm -rf $f ; done


Most of these were generated by spam addresses. (mail)

No comments: