Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all writable files in the current directory

Tags:

file

linux

bash

I want to quickly identify all writable files in the directory. What is the quick way to do it?

like image 715
vehomzzz Avatar asked Mar 22 '10 12:03

vehomzzz


People also ask

How do I find writable folders?

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).

What are world-writable files?

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.

What is world-writable directory in Linux?

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.


4 Answers

find -type f -maxdepth 1 -writable 
like image 64
matja Avatar answered Sep 23 '22 18:09

matja


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)
  • no prefix - exact specification (222 would mean no permssions other than write)
like image 21
Dennis Williamson Avatar answered Sep 20 '22 18:09

Dennis Williamson


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.$/'
like image 37
ghostdog74 Avatar answered Sep 23 '22 18:09

ghostdog74


-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
like image 41
Paul R Avatar answered Sep 20 '22 18:09

Paul R