I want to generate a random existing path to cd
and write file in it, if possible random from a specified root (the point is that can be used like cd /home/foobar/$RANDOM
).
I think I can do this by listing all paths with ls and awk with this command, according to ls command: how can I get a recursive full-path listing, one line per file?
ls -R /path | awk '
/:$/&&f{s=$0;f=0}
/:$/&&!f{sub(/:$/,"");s=$0;f=1;next}
NF&&f{ print s"/"$0 }'
And giving result line per line to $(dirname "${LINE_FILE}")
and finishing by purging dupes.
It should work but I need generate a lot of random existing paths and I hope a quicker solution exist (this generation may take a lot of time, worky but dirty). Any better ideas?