Skip to content

Instantly share code, notes, and snippets.

@skalahonza
Last active December 26, 2020 09:49
Show Gist options
  • Save skalahonza/18974b9d1f9d79b171e052ff320594ba to your computer and use it in GitHub Desktop.
Save skalahonza/18974b9d1f9d79b171e052ff320594ba to your computer and use it in GitHub Desktop.
Recursive LS. Created as a part of a cybersecurity challenge.
#!/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