0

I am using Linux and I want to create a list of files stored in folder and sub-folders with the filenames and their absolute locations concatenated as one string e.g. (/A/B/C/file.ext) some modification of:

ls -lR $PWD/* | awk '{printf(" %s/%s\n", ENVIRON["PWD"], $9); }'

to produce output where the PWD "current location" is replaced with the files absolute path.

αғsнιη
  • 41,407

2 Answers2

1

Just use find.

find $(pwd) -type f -not -path '*/\.*'

This lists all the files in the cwd with their full paths

Alex
  • 1,958
  • 1
    Why the -not part? This would exclude hidden files, which wasn't stated by the OP. – bxm Jan 04 '22 at 12:31
  • because they did not state that there should be absolute file paths with . , and that may cause some more trouble for OP – Alex Jan 04 '22 at 12:33
  • 1
    More to the point, @bxm, the command used by the OP will exclude hidden files, so it is reasonable to provide alternatives that would produce the same output. – terdon Jan 04 '22 at 12:39
  • That assumes that the current working directory doesn't contain space, tab, newline or wildcard characters and is not hidden itself. With some find implementations, that can fail to exclude hidden files / dirs whose name is encoded in a charset different from that of the current locale. Note that it still descends into hidden dirs even if it excludes all files in there for output. – Stéphane Chazelas Jan 04 '22 at 15:07
0

With zsh:

print -rC1 ~0/**/*(ND)

Would print raw on 1 Column the paths of all non hidden files in ~0 (same as $PWD) sorted lexically. You could do the same with GNU find and sort with:

LC_ALL=C find "$PWD" -mindepth 1 -name '.*' -prune -o -print0 |
  sort -z |
  tr '\0' '\n'

That assumes however that the base name of $PWD does not start with ..

On FreeBSD, you'd be able to do:

find "$PWD" -depth +0 '(' -name '.*' -prune -o -print0 ')' |
  sort -z |
  tr '\0' '\n'