Wednesday, April 10, 2013

Finding (and fixing) files with undesirable permissions

I use a few programs that create files that are not group read/writable; this is an issue when working in a group environment (especially with Knime where important files are locked this way which prevents other users from even opening your workspaces). Here's a find command that'll locate these files:
find . ! -perm /g+r -exec ls -lh {} \;
view raw gistfile1.sh hosted with ❤ by GitHub
This command executes 'ls -lh' on each of the files to show the current permissions (would probably be more efficient to push into xargs to run ls on multiple files at once). The next find command will update the permissions on those files:
find . ! -perm /g+rw -exec chmod g+rw {} \;
view raw gistfile1.sh hosted with ❤ by GitHub
Of course, you can just run chmod recursively (chmod -R g+rw *), but this isn't always what you want.