Monthly Archives: April 2012

UNIX find writeable files – more creative

In a follow-up to my previous post, I got tired of typing things.  And so I came up with this script:



# Put arguments into an array

# If no arguments, set firt value to current dir.
if [ -z "${args[0]}" ]; then

# Loop over supplied paths and find writeable files
for arg in $args; do

  find $arg -type f -perm /u=w  | grep -v "\.class" | grep -v tmp-bin | \
grep -v aTest | grep -v fixToStuff | grep -v build/ | grep -v gensrc/ | \
grep -v Reference | grep -v "~" | grep -v "classes" | grep -v "buildtree"



My only detail to sort out was exactly how to refer to $@.  Apparently if you quote it (being exactly “$@”) that takes all the arguments as a single string.  Unquoted, it takes them separately and gets what I’m looking for.

As you can see, I also have a lot of cruft I don’t want to see in my results, so I use good ol’ “grep -v” to weed it out.  Yes, I know there is a way to use egrep to make that all one command, but for some reason it doesn’t always want to play nicely for me.  So in a classic “eff it, let the script deal with it” I just chain some pipes.  I think if I had thousands of files to sort through, this would suck.  But I don’t, so it doesn’t.