This is a multipart blog article series where I am going to explain the concepts of shell scripting and how to write a shell script in Linux, UNIX or Mac based systems. You can also follow this tutorial blog using windows but for that you have to install a bash from.
In this article we will see, that how can we check different properties related to a file.
- If we want to keep the cursor on the same line after printing the echo command, we can do this by
echo –e “Enter any thing : \c”. Here\cis being used to keep the cursor on the same line and if we do not use–eflag after echo then\cwill also get printed on the screen, and the cursor will go in the next line. - If we want to check the file exist or not then in
if conditionwe can use-eflag for it. - Similarly
-fflag is used inif conditionto check, that if file exist and is it regular file or not. - In the same way if we want to check for the directory we can use
-dflag inif condition. - There are two types of file
block specialandcharacter special- Block special file is the file which consists of binary data, pictures, videos etc.
- Character special file is the file which consists of characters, some data or code.
- To check it the file is block special we can use
-bflag inIf conditionand to check for character special file we use-cin if condition.
- If we want to check that whether the file is empty or not then we use
-sflag - If you want to check that file has read permission then use
-rflag. If you want to check that file has write permission then use-wflag, and if you want to check that whether the file has execute permission or not then use-xflag.
Practical code file related to this article
So, this was all about file test operator. Hope you liked it and learned something new form it.
If you have any doubt, question, quires related to this topic then or just want to share something with me, then please feel free to contact me.
📱 Contact Me
Twitter
LinkedIn
Telegram
Instagram
Top comments (0)