osx - mdfind -onlyin not working in hidden directories recursvily? How to use it properly?
2014-07
I am trying to find all files named doc.py
in one of my virtualevns (called data_science
), which are all in hidden directory .virtualenvs
under /Users/adni
and so I go:
mdfind -onlyin data_science -name doc.py
it returns NOTHING.
One hint is thtat is not working recursivly or has some problems with hidden dirs. If it matters I run it in zsh shell.
I think Spotlight doesn't index files or directories whose name starts with a period, or at least they are not shown by mdfind
.
I couldn't find any documentation about it, but for example mdfind kMDItemFSName=.bash_history
doesn't find ~/.bash_history
either. If you run sudo opensnoop
in one shell and mkdir .a;touch .a/{1..1000};mdimport .a
in another shell, you'll see that files in .a
are not opened, but if you run mkdir a;touch a/{1..1000};mdimport a
, files in a
are opened.
I am doing something I always do in Bash:
set | grep -i path
and the output is
Binary file (standard input) matches
What's wrong? grep --help
works, and set | more
works too.
Do this:
set > /tmp/zshset
Then open /tmp/zshset
in your favorite editor. Look for IFS
.
The default value for this, per the zshparam
man page, is default space, tab, newline and NUL. This last one is causing the trouble. grep
sees the NUL (ascii 0, displayed often as ^@
) and thinks that this is a binary file.
Possible solutions:
- Set IFS to some other value. This might cause problems if something else you do expects that NUL is a valid delimiter.
- Use
grep -a
as suggested by KeithB (or its equivalent--binary-files=text
) - Create a new alias for yourself which uses
grep -a
to save yourself a little bit of typing - Adapt to looking at your PATH through other means (e.g.
env | grep -i path
,echo $PATH
) -- I think the other solutions are simpler
I'm not sure what is going on, but you can pass the -a
flag to grep to force it to treat its input as text, regardless of what it thinks that it is.
Another workaround if your grep
doesn't implement -a
is to do:
$ set | cat -v | grep foo