2

i just today migrated to linux and i would like to know how to do this with ls command (ar what you thing is best). The idea is to obtain all files with full path in a directory, including subdirectories... The cmd command i was using is:

dir /b /s /a:-D
5
  • Is the output of find what you're looking for?
    – muru
    Jun 29, 2018 at 2:23
  • 2
    ... or find . -not -type d (to correspond to the /a:-D) maybe? Jun 29, 2018 at 2:29
  • almost!, it gives me relative paths, i want full paths, at least back to home Jun 29, 2018 at 2:47
  • so find "$PWD" -not -type d should do that I think Jun 29, 2018 at 2:50
  • The propesed command gives this error message on UNIX: find: bad option -not
    – schily
    Jun 29, 2018 at 3:49

1 Answer 1

5

As far as I can tell, your dir command descends into subdirectories (/S), skipping headers and summaries (/B) and omitting files whose directory attribute is set (/A:-D)

The portable way to do that in Linux would be via the find command - it descends into subdirectories by default, and can be made to omit directories by adding -not -type d (! may be used as a synonym for -not)

By default, it reports paths relative to the starting point, so to get absolute paths you can use the shell's present working directory variable PWD:

find "$PWD" -not -type d

If you are using a shell that supports recursive pattern matches (aka "globstar") and glob qualifiers, there are other options - in zsh for example you could do

ls -1d **/*(^D:A)

or simply

printf '%s\n' **/*(^D:A)

You may also want to consider whether you really want "not directories" or "plain files":

find "$PWD" -type f

or (zsh)

printf '%s\n' **/*(.:A)
5
  • You did never test your find command on UNIX, since this results in: find: bad option -not
    – schily
    Jun 29, 2018 at 3:51
  • 3
    @schily the question only asks about Linux, and the answer only claims to address Linux. Jun 29, 2018 at 5:19
  • There is still no reason to give a nonportable answer and to mention a nonhelpful alias instead of the official method.
    – schily
    Jun 29, 2018 at 7:59
  • @schily if you have a portable solution, why don't just post an answer yourself?
    – phuclv
    Jul 21, 2018 at 12:40
  • there are downvoting trolls that downvote all answers that inform about vendor lock ins caused by GNU tools.
    – schily
    Jul 21, 2018 at 15:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .