I want to quickly identify all writable files in the directory. What is the quick way to do it?
To use the same short syntax for finding directories writable by some other user, use sudo -u username find ... , i.e. change into that other user before running find (but see an answer to a related question for caveats and better alternatives).
Description. Data in world-writable files can be read, modified, and potentially compromised by any user on the system. World-writable files may also indicate an incorrectly written script or program that could potentially be the cause of a larger compromise to the system's integrity.
Any directories that are listed in the output should have the sticky bit set, which is denoted by a t in the directory's permission bits. A world-writable directory with the sticky bit set ensures that even though anyone may create files in the directory, they may not delete or modify another user's files.
find -type f -maxdepth 1 -writable
The -writable
option will find files that are writable by the current user. If you'd like to find files that are writable by anyone (or even other combinations), you can use the -perm
option:
find -maxdepth 1 -type f -perm /222
This will find files that are writable by their owner (whoever that may be):
find -maxdepth 1 -type f -perm /200
Various characters can be used to control the meaning of the mode argument:
/
- any permission bit-
- all bits (-222
would mean all - user, group and other)222
would mean no permssions other than write)to find writable files regardless of owner, group or others, you can check the w
flag in the file permission column of ls.
ls -l | awk '$1 ~ /^.*w.*/'
$1 is the first field, (ie the permission block of ls -l) , the regular expression just say find the letter "w" in field one. that's all.
if you want to find owner write permission
ls -l | awk '$1 ~ /^..w/'
if you want to find group write permission
ls -l | awk '$1 ~ /^.....w/'
if you want to find others write permission
ls -l | awk '$1 ~ /w.$/'
-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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With