I need grep
to match exactly in the list of results from the ls
.
For example, if I ls
directory and here are the results:
system sys sbin proc init.rc init.mahimahi.rc init.goldfish.rc init
I would like to grep
see if a file named "init" exists. I need grep
to return only one result. There is only one file in the list called "init".
I am performing this operation on an Android device. So here is the complete command:
adb shell ls / | grep -E "^init$"
I need to check for the existence of a directory on an Android device, and then perform an action if the directory exists.
I did this before using find
in the script package, but I need to do this on linux using bash
, and I want an exact match. This will avoid the problem if there is another directory or file containing the line I'm looking for.
I tried the sentences in the following links, but they all do not return the result when I give "init" as a parameter.
how-to-grep-the-exact-match
match-exact-word-using-grep
source share