bashcommand-linefindls

How can I get a recursive full-path listing, one line per file?


How can I spit out a flat list of recursive one-per-line paths?

For example, I just want a flat listing of files with their full paths:

/home/dreftymac/.
/home/dreftymac/foo.txt
/home/dreftymac/bar.txt
/home/dreftymac/stackoverflow
/home/dreftymac/stackoverflow/alpha.txt
/home/dreftymac/stackoverflow/bravo.txt
/home/dreftymac/stackoverflow/charlie.txt

ls -a1 almost does what I need, but I do not want path fragments, I want full paths.


Solution

  • If you really want to use ls, then format its output using awk:

    ls -R /path | awk '
    /:$/&&f{s=$0;f=0}
    /:$/&&!f{sub(/:$/,"");s=$0;f=1;next}
    NF&&f{ print s"/"$0 }'