I need to grep
for an exact match on a list of results from an ls
command.
For example, if i ls
a directory and here are the results:
system
sys
sbin
proc
init.rc
init.mahimahi.rc
init.goldfish.rc
init
I would like to grep
to see if a file exists that is named "init". I need the grep
to only return the one result. There is only one file named "init" in the list.
I am performing this operation on an android device. So here is the full command:
adb shell ls / | grep -E "^init$"
I need to check the existence of a directory on the android device and then perform an action if the directory exists.
I have done this before using find
in a batch script, but i need to do this on linux using bash
and i want an exact match. This will avoid the issue if there is another directory or file that contains the string i am searching for.
I have tried the suggestions in the following links, but they all return no result when i give "init" as the parameter.