Last active
December 26, 2020 09:49
-
-
Save skalahonza/18974b9d1f9d79b171e052ff320594ba to your computer and use it in GitHub Desktop.
Recursive LS. Created as a part of a cybersecurity challenge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
recurse () | |
( | |
recurse2 () | |
{ | |
[ $_recurse_stop -eq 1 ] && return | |
cd "$1" || return | |
pwd ## do whatever you want in the pwd | |
for entry in $(ls); | |
do | |
[ "." = "$entry" -o ".." = "$entry" ] && continue; | |
[[ -f "$entry" ]] && echo "$(pwd)/$entry" | |
[ -d "$entry" -a ! -h "$entry" ] && recurse2 "$entry"; | |
done | |
cd .. | |
} | |
_recurse_stop=0 | |
trap '_recurse_stop=1' 2 | |
recurse2 "$1" | |
) | |
recurse "/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment