Linux - File test operator
49K views
Nov 28, 2024
Linux - File test operator
View Video Transcript
0:00
Now till now the operators which we have used were running into the single program or a single file
0:06
Now here I'm going to show you how we can run and test a particular file operator, which we have already discussed
0:14
But let us see which are the file operators we have and how we can test a particular file and what are the clauses we can set for testing a particular file
0:23
So I can check with a query area like if I want to check a particular file is a file or a particular directory
0:29
a particular directory. Now for example I have a name or I don't know whether it is a file or a
0:33
directory. I can use hyphen d and then the file name so it will show me whether it is a file
0:39
or a directory. If hyphen d is true means it is a directory. If it is false it means it is not a
0:45
directory it is a file. Next we have that is hyphen f and file. We can check whether the file
0:52
is an ordinary file or a special file. The ordinary file means we generally keep the data into it
0:59
The created by the user, they are the ordinary files, though they are not a special file or a different kind of file we use into the Linux operating system
1:06
So we can check the kind of a file we have. If hyphen f is true, that means it is an ordinary file
1:12
If not, means it is a special kind of file we have, like your tar files, which is a backup file
1:17
or a particular, we can say a shell file, we can go for any files, right
1:23
Next we have hyphen g. Now we have seen how we can use the sticky bit and geo-id bits
1:28
Now if I want to check whether my file is assigned with a G-O-ID permission or not
1:33
So if I want to check it, I can give hyphen G-M the file name
1:37
It will check for my G permission is allocated or assigned on my file or not If it is true it is a sign If it is false it is not assigned Let us check how we can use this particular operator into our Linux shell
1:52
Same here we can use one of the relational operator into the file, same into the same file I have just modified the same
2:00
Same I'm going to ask for the first number feed it into red, a variable, second number, fit it into the B variable
2:07
But here I'm going to use equal to sign which you. symbolize that it is going to check for the equality of both the operants or we can say
2:16
both the variables data or values if both are same it will give you value are equal
2:23
if they are not equal if you know the condition is false it will give you it is not equal
2:30
let us check about it as such if dot sh so first value is two second values again two
2:38
it is showing me values are equal. Again, if I run the same, first value is three, second value is two, it is showing you
2:45
this are not equal. This is completely checked by or checked by your same file and the same operator which we have used
2:54
This is your string operators which we use. So this is how generally we can check for any of your operators
3:02
You can use any of the operators in condition or any conditions where you define
3:06
So different, like your different operators, you can also use this operators
3:10
It will accept your value for this. You do not have to define anything else
3:14
So this is how we have seen these string operators. So next we are going to check for the file test operators
3:20
We'll check for the files into, you know, directory whether it is a file or a particular folder that we can check by using some shell command
3:29
So let us check how to do it
#Programming
#Software