Skip to content

Instantly share code, notes, and snippets.

@t-nissie
Last active June 6, 2016 02:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t-nissie/8491009 to your computer and use it in GitHub Desktop.
Save t-nissie/8491009 to your computer and use it in GitHub Desktop.
Mac OS Xとかでファイルとディレクトリの拡張属性xattrを再帰的にすべて消す高速なPythonスクリプトdelxattr.py
#!/usr/bin/env python
# delxattr.py recursively removes all extended attributes (xattr) from
# all files and directories under the current or given directory.
# In the latest Mac OS X, you can do the same thing with "xattr -rc".
# See a help of xattr with "xattr -h".
# Author: Takeshi NISHIMATSU
# Gist: https://gist.github.com/t-nissie/8491009
# Example1$ delxattr.py
# Example2$ delxattr.py ../foo
# Example3$ delxattr.py ~/foo
# Example4$ delxattr.py /tmp/foo/bar
# Copying: delxattr.py is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY. You can copy, modify and
# redistribute delxattr.py, but only under the conditions described
# in the GNU General Public License (the "GPL"). For more detail,
# see http://www.gnu.org/licenses/gpl.html .
##
import sys
import os
import xattr
try:
dir = sys.argv[1]
except IndexError:
dir = "."
for dpath,dnames,fnames in os.walk(dir):
for fname in dnames+fnames:
f = os.path.join(dpath,fname)
if os.path.islink(f):
continue
xattr.xattr(f).clear()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment