Search code examples
pipeheadls

feed the output of ls command to head


I'd like to print the first 10 lines of the output of an ls command.

I tried ls | head 10, which obviously didn't work.

Then I tried ls | xargs -0 head 10, hoping that it'd work, but it didn't either. (It seems to work to some extent, but the thing prints everyhting on the same line, which is kind of hard to read!)

So does anyone happen to know how to 'grab' only the first 10 lines of an ls's output?

Thanks,


Solution

  • ls | head -10
    

    or

    ls | head -n 10