I want to print a structure of a folder with shell script. So it would look like this
File : linux -3.14/COPYING
File : linux -3.14/CREDITS
Directory : linux -3.14/Documentation
File : linux -3.14/Documentation/00 - INDEX
Directory : linux -3.14/Documentation/ABI
File : linux -3.14/Documentation/ABI/README
and this is my script. The problem is that it prints out all files and folders for the current directory but it will not print for the subfolders. Maybe I do recursion wrong
dirPrint() {
# Find all files and print them first
file=$1
for f in $(ls ${file}); do
if [ -f ${f} ];
then
path="$(pwd)/$f"
echo "File: $path"
fi
done
# Find all directories and print them
for f in $(ls ${file}); do
if [ -d ${f} ];
then
path="$(pwd)/$f"
echo "Directory: $path"
echo " $(dirPrint "$path")"
fi
done
}
if [ $# -eq 0 ]; then
dirPrint .
else
dirPrint "$1"
fi
And also what is the difference between using $1, "$1" and "${1}"?
treecommand. This is an exercise so i don't know if my tutor hastreecommand in their linux