Skip to content

Instantly share code, notes, and snippets.

@Nicolab
Created July 25, 2014 15:50
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 Nicolab/2f3fe0a939c009466fbe to your computer and use it in GitHub Desktop.
Save Nicolab/2f3fe0a939c009466fbe to your computer and use it in GitHub Desktop.
function traverse() {
find $1 -mindepth 1 -maxdepth 1 ! -type d -exec echo "$2"{} \;
for d in $(find $1 -mindepth 1 -maxdepth 1 -type d ! -name ".")
do
# if you just need files comment out next line
echo "$2$d"
traverse "$d" "${2} "
done
}
traverse $1
@Nicolab
Copy link
Author

Nicolab commented Jul 25, 2014

Output

  • ./test.sh
  • ./testA
    • ./testA/dat2
    • ./testA/dat1
    • ./testA/testB
      • ./testA/testB/dat4
  • ./testC
    • ./testC/dat3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment