<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def rm(pattern):
 """Recursively remove a file or dir by pattern."""

    paths = glob.glob(pattern)
    for path in paths:
        if path.startswith('.git/'):
            continue
        if os.path.isdir(path):
            def onerror(fun, path, excinfo):
                exc = excinfo[1]
                if exc.errno != errno.ENOENT:
                    raise

            safe_print("rmdir -f %s" % path)
            shutil.rmtree(path, onerror=onerror)
        else:
            safe_print("rm %s" % path)
            os.remove(path)