Skip to content

Instantly share code, notes, and snippets.

@guicattani
Created September 10, 2019 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guicattani/377eec1ebfec6f3cc39bd6e078cf1d6c to your computer and use it in GitHub Desktop.
Save guicattani/377eec1ebfec6f3cc39bd6e078cf1d6c to your computer and use it in GitHub Desktop.
Script to traverse through all folders and files inside a given folder, second argument is indentation level
#!/bin/bash
folder="$1"
add_space_indentation () {
for i in $(eval echo "{1..$1}")
do
echo -n '-'
done
}
list_directories (){
add_space_indentation $(($2))
echo "FILES IN $1"
for f in $1/*
do
if [ -d "$f" ] #directory
then
list_directories $f $(($2 + 2))
else #file
add_space_indentation $(($2))
echo "$f"
fi
done
}
list_directories $folder 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment