Please help. I am a student and I found this question online, trying to practice and learn.
I am creating a program that will echo each entry in a given directory. If the entry in the directory is a file, it will echo its size. If the entry is a directory it will echo how many items are in that directory. My program below will echo the files in the given directory. My question is how to echo the size of the files and echo how many items in the directory. My program below
Thank you!
#! /bin/bash
# Files Directory
read -p "Enter a Directory or File: " entry
target="$entry"
let count=0
for f in "$target"/*
do
echo $(basename $f)
let count=count+1
done
echo "Files in the Directory: $count"
exit 0
-f
and-d
. – glenn jackman Mar 14 '18 at 16:07stat
or `wc. – glenn jackman Mar 14 '18 at 16:07