linux - Find command doesn't work for certain subdirectories
2014-07
I just downloaded some source code from a repository and I'm trying to locate a specific file in it. For simplicity, assume that the entire project has the following directory hierarchy
project
/ \
src docs
/ \ \
other test2.h test1.h
I navigate to the project directory and then use the following command
sudo find . -name test1.h
This works perfectly.
However, the following command doesn't work:
sudo find . -name test2.h
The find command is able to locate test1.h but not test2.h. Why could this be? Is it possible for one of the folders to be non-searchable?
Note, I'm doing all of this on a linux machine
You don't have the r
or x
access on src
directory.
How to find the executable files under a certain directory in linux?
use the -executable
option:
find <dir> -executable
if you want to find only executable files and not searchable directories, combine with -type f
:
find <dir> -executable -type f
EDIT:
checking with the comments i see there’s no type x
. i’m sorry, this was my mistake. checking for executable files can be done with -perm
(not recommended) or -executable
(recommended, as it takes ACL into account).
Use the find's -perm
option. This will find files in the current directory that are either executable by their owner, by group members or by others:
find . -perm /u=x,g=x,o=x
Edit:
I just found another option that is present at least in GNU find 4.4.0:
find . -executable
This should work even better because ACLs are also considered.
A file marked executable need not be a executable or loadable file or object.
Here is what I use:
find ./ -type f -name "*" -not -name "*.o" -exec sh -c '
case "$(head -n 1 "$1")" in
?ELF*) exit 0;;
MZ*) exit 0;;
#!*/ocamlrun*)exit0;;
esac
exit 1
' sh {} \; -print