-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_file_info.sh
More file actions
30 lines (28 loc) · 1017 Bytes
/
print_file_info.sh
File metadata and controls
30 lines (28 loc) · 1017 Bytes
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
#!/bin/bash
# This script prints the information about a file
# Check if the file exists
for file in $(ls $1); do
if [ -f $file ]; then
echo "File: $file"
echo "Size: $(ls -lh $file | awk '{print $5}')"
echo "Owner: $(ls -lh $file | awk '{print $3}')"
echo "Group: $(ls -lh $file | awk '{print $4}')"
echo "Permissions: $(ls -lh $file | awk '{print $1}')"
echo "Last modified: $(ls -lh $file | awk '{print $6, $7, $8}')"
echo "Type: Regular file"
echo
elif [ -d $file ]; then
echo "File: $file"
echo "Size: $(ls -lh $file | awk '{print $5}')"
echo "Owner: $(ls -lh $file | awk '{print $3}')"
echo "Group: $(ls -lh $file | awk '{print $4}')"
echo "Permissions: $(ls -lh $file | awk '{print $1}')"
echo "Last modified: $(ls -lh $file | awk '{print $6, $7, $8}')"
echo "Type: Directory"
echo
else
echo "File: $file"
echo "Type: Unknown"
echo
fi
done