Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.