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\c
is being used to keep the cursor on the same line and if we do not useβe
flag after echo then\c
will 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 condition
we can use-e
flag for it. - Similarly
-f
flag is used inif condition
to 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
-d
flag inif condition
. - There are two types of file
block special
andcharacter 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
-b
flag inIf condition
and to check for character special file we use-c
in if condition.
- If we want to check that whether the file is empty or not then we use
-s
flag - If you want to check that file has read permission then use
-r
flag. If you want to check that file has write permission then use-w
flag, and if you want to check that whether the file has execute permission or not then use-x
flag.
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)