Find all writable files in the current directory
find -type f -maxdepth 1 -writable
Find files that has write permission for current user
Your second command is correct, you just have to print the paths. Usually -print
doesn't have to be mentioned, but with a few options like -exec
you have to explicitly specify that you want to print the found paths.
find "$DIR" -type f -exec test -w {} \; -print
You may wonder: »Why does this print only writeable files?«
find
uses short-circuit evaluation – the next option is only evaluated if the preceding option succeeded.
Example: In the command find -type f -user USER
the check -user USER
will only be performed on files, not on directories as -type f
fails for directories.
The -exec cmd
option also acts as a check – the exit status of cmd
will be used to determine whether the check passed or not.
Example: find -exec false \; -user USER
won't ever perform the check -user USER
since the program false
never succeeds.
In your case that means that -print
will only be executed if test -w
succeeded.
BASH - Find all world writable files referenced in a set of files
The major slowness certainly comes from the find /
, scanning the entire filesystem. It will be faster to do the converse:
- Extract all the absolute paths from the init scripts
- Using an appropriate regex, for example excluding matches where a # occurs earlier on the same line
- For each extracted potential path, check that:
- The file actually exists
- The file is world writable
The result should be significantly faster.
Listing files and directories writable by the group in Linux
Something like
find /dir/ -perm /g=w
Or, for output like ls -l
find /dir/ -perm /g=w -exec ls -lLd {} +
Find writable files in Mac OS
Writable by whom?
If you mean writable by any, you can use:
find . -type f -perm -0222
or
find . -type f -perm -ugo=w
If you mean writable by other
, use:
find . -type f -perm -0002
or
find . -type f -perm -o=w
LINUX - shell script finding and listing all files with rights to write in directory tree
The effect of your script is to find the files below the current working directory that are not directories and are writeable to the current user. This can be achieved with the command:
find ./ -type f -writable
The advantage of using -type f
is that it also excludes symbolic links and other special kinds of file, if that's what you want. If you want all files that are not directories (as suggested by your script), then you can use:
find ./ ! -type d -writable
If you want to sort these files (added question, assuming lexicographic ascending order), you can use sort
:
find ./ -type f -writable | sort
If you want to use these sorted filenames for something else, the canonical pattern would be (to handle filenames with embedded newlines and other seldom-used characters):
while read -r -d $'\0'; do
echo "File '$REPLY' is an ordinary file and is writable"
done < <(find ./ -type f -writable -print0 | sort -z)
If you're using a very old version of find
that does not support the handy -writable
predicate (added to v.4.3 in 2005), then you only have file permissions to go on. You then have to be clear about what you mean by “writable” in the specific context (writable to whom?), and you can replace the -writable
predicate with the -perm
predicates described in @gregb's answer. If you decide that you mean “writable by anyone” you could use -perm /u=w,g=w,o=w
or -perm /222
, but there's actually no way of getting all the benefits of -writable
just using permissions. Also note that the +
form of permission tests to -perm
is deprecated and should no longer be used; the /
form should be used instead.
find world-writable files with powershell
Check the appropriate properties instead of converting the Get-Acl
output to a string. This works on all Windows versions:
Get-ChildItem -Recurse -Force | Where-Object {
$acl = Get-Acl $_.FullName
$acl.Access | Where-Object { $_.IdentityReference -eq 'Everyone' }
}
You can expand the check to actually detect ACEs that allow write access to "Everyone" (the above would detect any ACE for "Everyone"):
Get-ChildItem -Recurse -Force | Where-Object {
$acl = Get-Acl $_.FullName
$acl.Access | Where-Object {
$_.IdentityReference -eq 'Everyone' -and
$_.AccessControlType -eq 'Allow' -and
$_.FileSystemRights -band 278
}
}
Beware, though, that DENY ACLs take precedence over ALLOW ACLs, and explicit ACLs take precedence over inherited ACLs, so "Everyone" may or may not actually have write access even if there is an ACE granting write access.
- ALLOW ACE without DENY ACE ⇒ access allowed (obviously)
- DENY ACE without ALLOW ACE ⇒ access denied (obviously)
- inherited ALLOW ACE and inherited DENY ACE ⇒ access denied
- explicit ALLOW ACE and inherited DENY ACE ⇒ access allowed
- inherited ALLOW ACE and explicit DENY ACE ⇒ access denied
- explicit ALLOW ACE and explicit DENY ACE ⇒ access denied
How to find force-writable files in Perforce
There are a variety of approaches to this problem. Start by reviewing the overall techniques here: https://community.perforce.com/s/article/3481
Bash check if all files in a folder are writable by www-data
You can use find
to find out:
find /tmp/logs -not -user www-data
But, to to change the owner of all the files, you can use recursive chown
:
chown -R /tmp/logs/* www-data
Related Topics
Differencebetween "Var=${Var:-Word}" and "Var=${Var:=Word}"
Could Not Load Shared Library Symbols for Linux-Vdso.So.1. While Debugging
On X64 Linux, Differencebetween Syscall, Int 0X80 and Ret to Exit a Program
How Bash Handles the Jobs When Logout
Linux Kernel: How to Capture a Key Press and Replace It with Another Key
What Is the Use of File Descriptor 255 in Bash Process
Change .Eclipse Folder in Linux
Run Shell Script When Saving a File in Sublime Text 3
Unix 'Alias' Fails with 'Awk' Command
Can't Run Sonar Server Caused by Elasticsearch Cannot Running as Root
Arm Inline Asm: Exit System Call with Value Read from Memory
Using Output of Awk to Run Command
Docker MACvlan Network, Unable to Access Internet
How to Replace to Apostrophe ' Inside a File Using Sed
How to Print a String to the Terminal in X86-64 Assembly (Nasm) Without Syscall