The file in question has rw-r--r--
permissions, which means it can be read by everyone. Only nobody
can write it, but that's irrelevant in this case, as you don't need to write to the file.
The message Permission denied
appears because you use the wrong command.
/etc/openvpn/test.txt | grep -c "test"
means that you tell the system to execute the file /etc/openvpn/test.txt
as a program, and feed the output of that program to the grep
command.
Because the file /etc/openvpn/test.txt
lacks the execute permission (it has only read permission for everybody and write permission for nobody
), the system can't execute it and you get the message Permission denied
. So there's no output from this command (the error message goes to standard error and not standard output, therefore you see it on the screen) and grep
receives an empty input, so it displays 0
as a result.
This command is wrong. I assume the file /etc/openvpn/test.txt
is not a program that can be executed, but it's just a text file which you want to be read by grep. In that case, you should use the following command:
grep -c "test" /etc/openvpn/test.txt
It means run the program grep
, and have that program read the file /etc/openvpn/test.txt
.