Find writable files in Mac OS - linux

I want to find (recursively) writable files in my directory. My operating system is MacOS.
I tried:
find . -type -writable
but the shell returns an error:
find: -type: -writable: unknown type
Why I got the error? Are there alternatives?

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

Related

what's meaning of `find \( -perm -04000 -o -perm -02000 \)`

I know this:
find . -perm -664
Search for files which have read and write permission for their owner and group,
and which other users can read.
but I can't figure out what is meaning of 04000 and 02000, maybe the lsattr could tell me? but I also have no idea about that.
THX.
I've come to the conclusion that both commands below give the same output:
SUID permission search command:
find / -perm -u=s -type f -ls 2>/dev/null
find / -perm -04000 -type f -ls 2>/dev/null
and also:
SGID permission search command:
find / -perm -g=s -type f -ls 2>/dev/null
find / -perm -02000 -type f -ls 2>/dev/null
Therefore find \( -perm -04000 -o -perm -02000 \) is searching for the permission bits of SUID and SGID. Documentation here: https://www.gnu.org/software/libc/manual/html_node/Permission-Bits.html

Fnd files that cannot be modified by others

I want my program to show me the files that can't be modified by others in the current directory. Here is what I have so far:
#!/bin/bash
find . -type f -perm u-w
I think you could use o-w permission for finding files not writable by others.
find . -type f -perm o-w

Find files which do not have read permissions for other

I want to get all files which do not have read permissions for others.
I've tried find . -type f -perm -o-r and find . -type f -perm -o
But they return all files. Seems I'm doing something wrong.
Thanks.
Just search for anything that doesn't have the read permission for others:
find -not -perm -o=r
You can use:
find . -type f ! -perm -o+r

Alternative way to find all files in a folder and subfolders

Is there any alternative for below command to find files in a folder and subfolders as well.
find . | egrep '\./[^/]+/[^/]+/[^/]+'
Note: I don't want directories I want to get only files
Additionally, you could specify list of files extensions as your search options:
find . -type f -name "*.js" -o -name "*.ros" -o -name "*.php"
Above example, would only display file names with *.ros, *.php, and *.js as file extensions under specific folder and subfolders.
Why don't you just use find?
I am not sure from your question if you want to limit the depth. If so:
find . -type f -depth 2 -print
If you just want to find files
find . -type f -print
If you just want to find directories
find . -type d -print
You can also use -ls if -print does not float your boat.
find . -type f -ls

Output directory name from linux find command

How do I get the name of a folder from a linux find commnad.
I have a command like this:
find /root/wgetlog -name -type d -empty
Whic produces the following results:
/root/wgetlog/smil3
/root/wgetlog/smil5
/root/wgetlog/smil4
how do I get just the name of the folder:
Example:
smil3
smil4
smil5
find /root/wgetlog -type d -empty -printf "%f\n"
If all you need is a relative path, then
{ pushd /root/wgetlog/; find . -name -type d -empty; popd; }
is the approach, especially if you do care about subdirectories of /root/wgetlog/*.
Use basename:
find /root/wgetlog -type d -empty -exec basename {} \;
You don't need -name.
You could also use sed to filter out the leading elements of each path:
$ find /usr/bin -type d
/usr/bin
/usr/bin/multiarch-i386-linux
/usr/bin/multiarch-x86_64-linux
/usr/bin/gda_trml2pdf
/usr/bin/gda_trml2html
...
$ find /usr/bin -type d | sed 's|.*/||'
bin
multiarch-i386-linux
multiarch-x86_64-linux
gda_trml2pdf
gda_trml2html
...
This might be more portable than using the -printf option of find, although that should not be an issue if you stick to Linux.
Disclaimer: this will fail horribly if you have newlines in your file/folder names. On the other hand, this snippet is probably not the only thing that would fail in that case...

Resources