-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay_files.sh
More file actions
35 lines (29 loc) · 1.01 KB
/
display_files.sh
File metadata and controls
35 lines (29 loc) · 1.01 KB
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
#!/bin/bash
# Prompt the user for the directory path
echo "Enter the directory path:"
read dir_path
# Check if the directory exists
if [ ! -d "$dir_path" ]; then
echo "The directory does not exist."
exit 1
fi
# Display the file information
echo "File Size (in kB) Date Security Owner"
for file in "$dir_path"/*; do
if [ -f "$file" ]; then
# Extract file information
file_name=$(basename "$file")
file_size=$(du -k "$file" | cut -f1)
file_date=$(stat -c %y "$file" | cut -d ' ' -f1)
file_security=$(stat -c %A "$file")
file_owner=$(stat -c %U "$file")
# Display the file information in the specified format
echo "$file_name $file_size $file_date $file_security $file_owner"
fi
done
# Calculate the total number of files and total space occupied
total_files=$(find "$dir_path" -type f | wc -l)
total_space=$(du -sh "$dir_path" | cut -f1)
# Display the total number of files and total space occupied
echo "Total number of files: $total_files"
echo "Total space occupied: $total_space"