Bash -F Test Condition
A regular file is a type of file which is stored in the file system. As a Linux user, you mostly use the regular files like text files, image files, etc. Here, we will test whether the file is regular through the Bash -f test condition. Let’s run the Bash script and the syntax to test the regularity of the file:
Let us take some random files and test the regularity of the file. Let’s run the following Bash script:
test -f LinuxHint.txt
echo $?
Output:
Upon running the previous script, we see 0 in the output. Hence, our file is regular. If your file is not regular, it gives us 1 in the output.
Let’s take one more example to clarify everything better. For instance, we can use the Bash -f test condition with an if-else statement.
test -f rufus-3.20.exe
If echo "rufus-3.20.exe"
then
echo "File is regular"
else
echo "File is not regular"
fi
Output:
After running the previous script, it tells you that your file is not regular.
Conclusion
In this tutorial, we used the Bash -f test condition to see how to check whether a file is regular or not using a Bash script. Regular files are those that the users easily execute. You can check if the file is regular by using the -f flag with the test command without opening the file. The test command contains various options to check the type of files in Linux.