I want to quickly identify all writable files in the directory. What is the quick way to do it?
-f
will test for a file
-w
will test whether it's writeable
Example:
$ for f in *; do [ -f $f ] && [ -w $f ] && echo $f; done
The problem with find -writable
is that it's not portable and it's not easy to emulate correctly with portable find
operators. If your version of find
doesn't have it, you can use touch
to check if the file can be written to, using -r
to make sure you (almost) don't modify the file:
find . -type f | while read f; do touch -r "$f" "$f" && echo "File $f is writable"; done
The -r
option for touch
is in POSIX, so it can be considered portable. Of course, this will be much less efficient than find -writable
.
Note that touch -r
will update each file's ctime (time of last change to its meta-data), but one rarely cares about ctime anyway.
for var in `ls`
do
if [ -f $var -a -w $var ]
then
echo "$var having write permission";
else
echo "$var not having write permission";
fi
done
If you want to find all files that are writable by apache etal then you can do this:
sudo su www-data
find . -writable 2>/dev/null
Replace www-data with nobody or apache or whatever your web user is.