-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileInfo.sh
72 lines (62 loc) · 1.15 KB
/
FileInfo.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
#!/bin/bash
echo "Enter file name"
read fname
if [ -z $fname ]
then
echo "File name not entered"
exit 1
fi
# Check if the file exists
if [ ! -e $fname ]
then
echo "File not found"
exit 1
fi
# Determine file type
if [ -f $fname ]
then
file_type="Regular File"
elif [ -d $fname ]
then
file_type="Directory"
elif [ -c $fname ]
then
file_type="Character device"
elif [ -b $fname ]
then
file_type="block device"
elif [ -l $fname ]
then
file_type="link type"
else
file_type="unknown"
fi
#Determine file permissions
if [ -r $fname ]
then
echo "Read present"
else
echo "Read not present"
fi
if [ -w $fname ]
then
echo "write present"
else
echo "write not present"
fi
if [ -x $fname ]
then
echo "execute present"
else
echo "execute not present"
fi
# Check file permissions
permissions=$(ls -l $fname | cut -c 1-10)
echo $permissions
owner_permissions=${permissions:1:3}
group_permissions=${permissions:4:3}
others_permissions=${permissions:7:3}
echo "File Type: $file_type"
echo "Owner Permissions: $owner_permissions"
echo "Group Permissions: $group_permissions"
echo "Others Permissions: $others_permissions"