LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-13-2013, 12:43 PM   #1
standard_output
LQ Newbie
 
Registered: Apr 2012
Posts: 16

Rep: Reputation: Disabled
Cannot 'find "[" -maxdepth 1 -wholename "/usr/bin/[" ! \( -perm /g+w,o+w \)'


Hello.

A few things up front: I am running this on RHEL 5.x-6.x. I am running this on 32 and 64-bit architectures.

I am trying to use 'find' to hunt for the '[' binary file. The command that I have been using is similar to this:

find "[" -maxdepth 1 -wholename "/usr/bin/[" ! \( -perm /g+w,o+w \)
Unfortunately, the "find" command does not find [. The mode of [ is 0755, so the perm stuff is not in the way.

Interestingly, this works:
find [
find "[" -maxdepth 1 ! \( -perm /g+w,o+w \)

As best as I can tell, it is the '-wholename "/usr/bin/["' portion that is goofing things up, and in particular, it is the '['. I have tried escaping it with "/usr/bin/\[", it doesn't help


So my question is this: What do I need to write in the "-wholename" argument to allow it to find "["?

For those asking: Why would I want to do this? Why would I want to find a file if I already know where it is?", here goes: This is part of a much larger series of bash scripts that (among many other things) hunt down many files, noting whether they are group/world writable (or whatever mode [symbolic or octal] is specified). The library behind it needs to be able to support pretty much any syntax that 'chmod' can support, and the -perm option of 'find' is pretty darn close to what 'chmod' can take. (this is why I did not use 'stat' or 'ls -l' or similar.) The program later can quickly leave the majority of the file's mode intact, but strip out (or add!) just whatever is specified in the -perm field.
 
Old 09-13-2013, 01:00 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by standard_output View Post
find "[" -maxdepth 1 -wholename "/usr/bin/[" ! \( -perm /g+w,o+w \)
You are mistaken about the meaning of "-wholename". The path is always started from one of the search paths given on the command line, and in this case will just be "[". There is no implied "$PWD" prefix.

Note that since the search path given on the command line is not a directory, find will not have anything to recursively descend into, so the "-maxdepth 1" is superfluous.

Last edited by rknichols; 09-13-2013 at 01:03 PM.
 
Old 09-13-2013, 01:34 PM   #3
standard_output
LQ Newbie
 
Registered: Apr 2012
Posts: 16

Original Poster
Rep: Reputation: Disabled
So would this be more appropriate?

Code:
find /usr/bin/ -maxdepth 1 -name "\[" ! \( -perm /g+w,o+w \)
 
Old 09-13-2013, 01:45 PM   #4
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Code:
find /bin /sbin/ /usr/bin /usr/sbin -name "[" ! \( -perm /g+w,o+w \)
but I don't understand ! here, as it returns 'good' things
I assume it was just a test, pardon the pun
 
Old 09-13-2013, 01:48 PM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by standard_output View Post
Code:
find /usr/bin/ -maxdepth 1 -name "\[" ! \( -perm /g+w,o+w \)
missed that, yes

but you might as well search all PATHS , if you are looking for executables with rouge permissions
infact, I would look at every file owned by root
 
Old 09-13-2013, 04:23 PM   #6
standard_output
LQ Newbie
 
Registered: Apr 2012
Posts: 16

Original Poster
Rep: Reputation: Disabled
Good point Firerat, regarding searching everywhere and all. The calling script already does this, by finding all files in a specific set of directories, adding them to an array, then using the instance of the find command in this thread to check the permissions of each file in the array. The idea is that if 'find' finds a file when it is building the array, and then fails to find it when searching with the ! -perms stuff, then the file's mode is bad and must be fixed. If the second 'find' does find it, then it is probably OK.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't locate object method "path" via package "Autom4te::Request" at/usr/bin/autom4te wjh513 Linux - Software 1 08-13-2010 02:31 PM
Error When performing Make: "/usr/bin/ld: cannot find -lpanel" paulmwiu Linux - General 6 08-28-2009 12:28 PM
script using "/usr/bin/cat error" produces "cannot open" in cron Dcrusoe Programming 6 07-22-2009 03:30 PM
problem "make"ing gtk+ "/usr/bin/env: perl -w" caid Linux - Newbie 8 07-29-2005 04:51 AM
what is "S" instead of "X" in the file permission when i look at /usr/bin/chsh? Linux_interest Linux - Newbie 4 08-28-2004 09:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration