-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_test_operator.sh
78 lines (63 loc) · 1.62 KB
/
file_test_operator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! /bin/bash
# File test operator
echo -e "Enter the name of file : \c" # \c use to keep the cursor on same line -e flag
read file_name
echo -e "Enter Directory name : \c"
read d_name
if [ -e $file_name ] # -e for if the file exists
then
echo "$file_name Found"
else
echo "$file_name not found"
fi
if [ -f $file_name ] # -f for if the file exists and its a regular file or not
then
echo "$file_name Found"
else
echo "$file_name not found"
fi
if [ -d $d_name ] # -d for if the directory exists or not
then
echo "$d_name Found"
else
echo "$d_name not found"
fi
if [ -b $d_name ] # -b for if the file is blockspecial exists or not
then
echo "$d_name Found"
else
echo "$d_name not found"
fi
if [ -c $d_name ] # -c for if the file is character special exists or not
then
echo "$d_name Found"
else
echo "$d_name not found"
fi
if [ -s $filename_name ] # -s check whether file is empty or not
then
echo "$file_name is not empty"
else
echo "$file_name is empty"
fi
# to check your file has read permission
if [ -r $filename_name ] # -r check whether file has read permission or not
then
echo "$file_name have read permission"
else
echo "$file_name have not read permission"
fi
# to check your file has write permission
if [ -w $filename_name ] # -r check whether file has write permission or not
then
echo "$file_name have write permission"
else
echo "$file_name have not write permission"
fi
# to check your file has executable permission
if [ -x $filename_name ] # -x check whether file has executable permission or not
then
echo "$file_name have executable permission"
else
echo "$file_name have not executable permission"
fi