Don't use command substition in that manner, you'll end up with problems when word splitting is applied. Just do
find /dev/ -regex '/dev/sd[a-z]+' ! -name 'sda'
If your true objective is to show base block devices, just look in /sys/block
.
Finding with ls
: first things first, ls | grep cisco
is a bit verbose, since cisco
isn't a regular expression. Try:
ls *cisco*
Using find
: along the same lines, -regex
is overkill with a simple, static pattern. How about:
find -name '*cisco*'
The quotes are required so the glob is interpreted by find
, not the shell. Also, -print
is required for many versions of find
, but is optional (and the default predicate) for others (e.g. GNU find
). Feel free to add it if you need it.
If you need to search for ‘cisco’ in the full pathname, you could try this:
find -path '*cisco*'
which is equivalent to find | fgrep cisco
.
Using find
with regular expressions: let's do that anyway, since this is what you want. Shamelessly copying from the GNU find
manpage:
-regex pattern
File name matches regular expression pattern. This is a match
on the whole path, not a search. For example, to match a file named
`./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
but not `f.*r3'.
What this means is that your regular expression is wrapped in an invisible ^...$
, so it must match every character in the full pathname of the file. So, as nwildner and otokan said in the comments, you should use something like:
find -regex '.*cisco.*'
And you don't even need the -regextype
for something this simple.
Best Answer
If you use the
-regex
flag instead of-name
you can specify the name as a regular expression: