Well as we know the shell allows us to have extreme control of our entire system, despite its roughness and how primitive it is for many compared to modern graphical interfaces. But it must be taken into account that it is a much more optimal way of working, although it requires greater technical knowledge. The problem with the GUI is not only that it has some limitations compared to the terminal, but you are also running an extra layer for the graphics that consume a lot of resources that will not be destined for the final task.
We have been launching some Mini tutorials of some of the possibilities that can be obtained from some simple commands. This is another one, and as you can see, they are simple practices that can be of great help in many cases. Well, in this case specifically we are going to check how with a few simple commands we can see if a file or several of them exist in our system or not. The steps for this are as follows:
[ -f /etc/httpd ] && echo "Existe" || echo "No existe"
As you can see, we have used the evaluation expressions for it. Basically what we have done in the example, although you can replace it with many other options keeping the syntax, is to evaluate if / etc / httpd exists in our system or not. In the case of existing, since the -f option returns a true value if it exists, an "Exists" message will be displayed thanks to the use of the echo command. While otherwise it will show "Does not exist". As simple as that…
You can also substitute -f for Other options, like -e, which will return true if it exists, but does not evaluate if it is a regular file. With -r something similar will also happen, but in this case it evaluates if it is a readable file. To see if it is writable use -w, -x to see if it is also executable, and -d to see if it is a directory ... The possibilities are many. You can even use the character! to deny the actions. For example, to check that there is no / etc / test file:
[ ! -f /etc/prueba ] && echo "No existe"