3

I have folder that apparently has millions of files inside it.

As result, dir command is running for minutes already without displaying anything.

I checked dir --help and tried to search for solution.

How can I list files in category - with streaming, so command starts showing something quickly also if folder has millions of files?

I have no idea what is in the affected folder.

8
  • 3
    Try ls -1f ...
    – pLumo
    Nov 30, 2022 at 11:52
  • 2
    ... Or try find
    – Raffa
    Nov 30, 2022 at 11:59
  • But find would require you know part of the filename if you should display it in "chunks", right? Nov 30, 2022 at 12:00
  • 1
    @pLumo ls -1f works! Feel free to make into an answer larger or smaller Nov 30, 2022 at 12:03
  • 1
    Thanks reducingactivity ... I'm glad it worked ... find doesn't sort by default i.e. first come first served ... While ls and dir sort files alphabetically by default and this delays the output but can be disabled by the option -f so ls -f and dir -f ... Both are small details but will make better answer when combined together ... @pLumo was the first to comment so please pLumo go ahead.
    – Raffa
    Nov 30, 2022 at 12:22

1 Answer 1

3

ls will sort its output alphabetically by default, so it needs to read the content of the whole directory, before it is shown.

You can avoid sorting by running ls with -U.

But, ls will also read the type of each file/directory to be able to color it. This has also an impact on the performance. Avoid this with -f flag.

-f     do not sort, enable -aU, disable -ls --color

I usually use

ls -1f

See also

3
  • what 1 is doing here? Nov 30, 2022 at 16:39
  • So the one column may be easily piped to another command which then doesn't have to parse output lines of multiple files.
    – ubfan1
    Nov 30, 2022 at 16:47
  • 1
    @ubfan1 afaik ls only outputs multiple columns when standard output is a terminal, not a pipe ("... otherwise, the output is listed one per line and control characters are output as-is." - according to info ls) Nov 30, 2022 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.