I am trying to grep for the mount output to see the options for the root directory.

Why the following pattern (whitespace before and after a slash) is not working (with and without extended grep)

$ mount | grep  '/s\//s' 
$ mount | grep -e '/s\//s' 
  • 1
    You are confusing forward slashes with backslashes ('\s/\s') - and also lower case -e with upper case -E – steeldriver Mar 2 at 8:54
  • nice thanks; if you post this I will accept your answer; – pkaramol Mar 2 at 8:55

You are confusing forward slash /s with backslash \s - and also lower case -e with upper case -E:

$ mount | grep -E '\s/\s'
/dev/sda3 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)

Note that \s is really neither a basic regular exression (BRE) nor extended regular expression (ERE) specifier - it really belongs to PCRE (Perl-compatible regular expression) - however at least GNU grep appears to support it in other modes.

  • what is the BRE or ERE compliant way for greping for whitespaces? – pkaramol Mar 2 at 9:03
  • 1
    @pkaramol [ \t] or or [[:blank:]] or [[:space:]] (the latter are equivalent except in a multiline context) – steeldriver Mar 2 at 9:08
  • @steeldriver Depending on the libraries used, [ \t] might match backslash and t and space rather than a tab and space. – Kusalananda Mar 2 at 11:26

To grep the output of mount for a single lone slash with GNU grep:

mount | grep -w '/'

With BSD grep, just use

mount | grep ' / '

There is no need for anything more fancy since the mount command would output the mount point with simple spaces around it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.