0

This is strange. I want only to grep line containing /run. But it returning other lines too.

  [root@s5 ~]# df -h | grep -w "tm"
    [root@s5 ~]# df -h | grep -w "tmpfs"
    tmpfs                    489M     0  489M   0% /dev/shm
    tmpfs                    489M  6.8M  483M   2% /run
    tmpfs                    489M     0  489M   0% /sys/fs/cgroup
    tmpfs                     98M     0   98M   0% /run/user/1001
    tmpfs                     98M     0   98M   0% /run/user/0
    [root@s5 ~]# df -h | grep -w "tmpf"
    [root@s5 ~]# df -h | grep -w "/run"
    tmpfs                    489M  6.8M  483M   2% /run
    tmpfs                     98M     0   98M   0% /run/user/1001
    tmpfs                     98M     0   98M   0% /run/user/0

1 Answer 1

6

man grep:

-w, --word-regexp Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore.

Works as expected, I say. If your intention is to get only the first match you should use

$ df -h | grep -w "/run$"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .