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

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

Related

Problems with understanding and combining linux terminal commands

First one :
We found several files and we have to copy that to kat4 and here is code, but it doesn't seem to work corectly
find /home/imk-prac/ -type f -size -13c -name '*\?plik\?*' -exec cp {} /home/inf-19/aduda/\*kat1\*/\*kat2\*/\*kat4\*/ \; 2> /dev/null
'cp' I assume that it is copy, but I don't know what 'exec' and '{}' do.
Second one:
find /home/imk-prac/ \( -type f -size -13c -name '*\?plik\?*' \) -o\( -type d -name '\[Kolo1\]*' \)2> /dev/null
Generally,I understand this line (except for '2' and '-o') , but I want to add looking for files which were modificated in less that 30 days and here is what I wanted to combine with upper command :
find /home/imk-prac/ -type f -mtime -30 -exec ls -l {} \; > /dev/null
As a result I wrote it down as:
find /home/imk-prac/ \( -type f -size -13c -name '*\?plik\?' -mtime -30 -exec ls -l{}\) -o \( -type d -name '\[Kolo1\]*' \) 2> /dev/null
but it doesn't work
Moreover, I wanted to add looking for files with speciefied quantity of symbols and I found this command:
grep -Po '(^|\s)\S{64}(\s|$)' file
But I have no idea how to combine all of those 3 upper commands.
I will be grateful for any help, thank you for your time!

Order of actions in find command

This is the action I want to take place:
find ~ -type f -not -perm 0600 -ls
But when I try to write it this way
find ~ -ls \( -type f -not -perm 0600 \)
In which I tried to override the evaluation sequence via () operators the -ls test option always performed before the evaluation of the expression in the parenthesis,the question is doesn't parenthesis have effect on test options of find command or what?

What does this xargs command do?

I'm very new to xargs and can't seem to understand what this command does. Specifically I get confused with the find part of it and the brackets. Any explanations are welcome.
xargs -I '{}' find '{}' -xdev -type d \( -perm -0002 -a ! -perm -1000 \)
All of this can be found in the xargs and find man pages
xargs -I '{}'
Is replace string, and will replace any occurrence of '{}' with the line from the input to xargs
find '{}'
Search the directory with the name held in '{}'
-xdev
Don't go to other filesytstems
-type d
Only search for directories
\(
Not 100% but i think these are just to group the last 2 args
-perm -0002 -a ! -perm -1000
Check permission contain 0002 and not 1000
-a is and
! is not
Look up permission bits if you are unsure what these represent.

Recursively set user permissions equal to group permissions without changing anything else

Currently works for me (inspired from here):
sudo find . \( \( -type d -o -type f \) ! -path ".git/*" \) -printf '%04m%p\0' | perl -n0e 'unless (/^.(.)\1/) {$p1=substr($_,1,1);$p2=substr($_,2,1);$p3=substr($_,3,1);$n=substr($_,4);system("sudo chmod $p1$p1$p3 $n");}'
But seems to be complex and very inefficient.
Thus, is it possible to achieve that in a more simple and/or efficient way?
Thanks!

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

Resources