Score:3

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

cn flag

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.

pLumo avatar
in flag
Try `ls -1f` ...
Raffa avatar
jp flag
... Or try `find`
Artur Meinild avatar
vn flag
But `find` would require you know part of the filename if you should display it in "chunks", right?
reducing activity avatar
cn flag
@pLumo `ls -1f` works! Feel free to make into an answer larger or smaller
reducing activity avatar
cn flag
@Raffa `find` also worked! Also feel free to post answer and I will at least upvote it.
reducing activity avatar
cn flag
@ArturMeinild apparently `find` can be used without arguments.
Raffa avatar
jp flag
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.
reducing activity avatar
cn flag
oh, somehow I never noticed that `dir` sorts - that would explain why trying to list several million files was not working well
Score:3
in flag

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

reducing activity avatar
cn flag
what `1` is doing here?
cc flag
So the one column may be easily piped to another command which then doesn't have to parse output lines of multiple files.
hr flag
@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`)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.