mkdir -p ~/Desktop/testdir touch ~/Desktop/testdir/f{1,2,3}.txt find -x ~/Desktop/testdir -print0 | xargs -0 stat -LF stat -x ~/Desktop/testdir/f1.txt which xattr # /opt/local/bin/xattr; sudo port install xattr (after installing MacPorts, http://www.macports.org/install.php) # store file permissions as additional Unix file metadata with xattr find -x ~/Desktop/testdir -print0 | while read -d $'\0' filename; do #find -x ~/Desktop/testdir -type f -or -type d -print0 | while read -d $'\0' filename; do fchmod="$(stat -f %p "$filename")"; \ fchown="$(stat -f %u:%g "$filename")"; \ xattr --set fchmod "$fchmod" "$filename"; \ xattr --set fchown "$fchown" "$filename"; \ #echo $fchown $fchmod; \ done find -x ~/Desktop/testdir -print0 | xargs -0 xattr --list find -x ~/Desktop/testdir -print0 | xargs -0 stat -LF # change file permissions & ownership sudo chown -R root:wheel ~/Desktop/testdir sudo chmod -R 700 ~/Desktop/testdir sudo find -x ~/Desktop/testdir -print0 | xargs -0 sudo stat -LF find -x ~/Desktop/testdir -print0 | xargs -0 xattr --list sudo find -x ~/Desktop/testdir -print0 | xargs -0 sudo xattr --list # restore file permissions & ownership sudo find -x ~/Desktop/testdir -print0 | while read -d $'\0' filename; do fchown="$(sudo xattr --get fchown "$filename" | awk '/fchown/ {print $2}')"; \ fchmod="$(sudo xattr --get fchmod "$filename" | awk '/fchmod/ {print $2}')"; \ sudo chown "$fchown" "$filename"; \ sudo chmod "$fchmod" "$filename"; \ #echo $fchown $fchmod; \ done find -x ~/Desktop/testdir -print0 | xargs -0 stat -LF find -x ~/Desktop/testdir -print0 | xargs -0 xattr --list
Never been to CodeSnippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
Save & restore file permissions with xattr (See related posts)
You need to create an account or log in to post comments to this site.
Related Posts
» Igniter clases for gallery in apache php mysql find awk lighttpd ruby rails ssh date perl regex shell textpattern svn http osx mac chicken css python google html bash subversion windows sql activerecord javascript expressionengine java chewy actionscript rubyonrails unix clear checkbox linux applescript cli database c text ajax circle image string xml terminal file classic array web center Cisco delphi administration clause check convert clamav chmod chown chatting charts china chart characters class classpath character cheatsheet
» Igniter clases for gallery in apache php mysql find awk lighttpd ruby rails ssh date perl regex shell textpattern svn http conditionals osx mac chicken css python google compiler html bash subversion windows clock sql activerecord javascript expressionengine java conditional actionscript rubyonrails unix clear linux comments applescript cli console database c text ajax circle codepage image string component xml terminal file com classic array web Cisco Connections cloud constant delphi administration column columns concatenate clause convert compile clamav chmod chown coda conf china class classpath cmdparser comma cnn con
» snippet in spam shell osx mac html bash unix code commandline web download convert textutil internet ed snippets snippet comment
» Switching firewall settings ... in shell osx mac bash unix ipfw firewall ruleset switch
» Delete WebKit search fields in shell osx mac bash unix safari webkit
» pdftotext in shell osx mac bash unix pdf text convert
Snippets (source code soon to be available) developed by Peter Cooper and powered by Ruby On Rails