I tried going to /
and using ls -d -R $PWD/* | grep searchforthistext
to find any directories or files in my computer with searchforthistext
, and give me their absolute path (since simply using ls -R | grep searchforthistext
would only list the names of directories and files, but wouldn't show me where they were). For some reason it did nothing at all; it didn't spit out an error message at me, it just couldn't find anything and went onto the next line awaiting my input.
As a test (in another directory so that I could limit the amount of files would show up to a reasonable number for the test) I ran ls -d -R $PWD/*
without grepping; this work successfully. Then I ran ls -d $PWD/* | grep searchforthistext
and was again successful. I did another test though and ran ls -R | grep searchforthistext
, and again, success.
As a final test I tried ls -d -R $PWD/* | grep searchforthistext
and noticed that it was finding files with searchforthistext
in the name and showing their absolute paths, but it was not working recursively (so effectively it was running doing the same thing as ls -d $PWD/* | grep searchforthistext
).
So to summarize, when using ls
I can use any two of -d $PWD/*
, -R
and | grep searchforthistext
successfully (so it doesn't seem to be an issue with two of them not working together), but when I try them all together, the recursion fails. I have no idea why this is.
find
instead ofls
. – muru Sep 10 '21 at 02:04ls
(and what to do instead)? – agc Sep 10 '21 at 02:34find / -name 'searchforthistext'
instead – Chris Davies Sep 10 '21 at 06:32