I encountered ls: write error: Broken pipe when I run ls -l | head in a directory containing too many files. I did not encounter that problem when running ls | head. I just wonder why -l option would cause that problem. Also I would like to know how to resolve that problem but still with long information of files printed.
To reproduce my issue, you can first open a within terminal provided by Jupyter Notebook,
and then run the following codes.
cd
mkdir test
cd test
for i in {1..200}; do touch $i; done
ls -l | head
Output is as follows.
total 0
-rw-rw-r-- 1 s1855106 s1855106 0 Apr 14 10:14 1
-rw-rw-r-- 1 s1855106 s1855106 0 Apr 14 10:14 10
-rw-rw-r-- 1 s1855106 s1855106 0 Apr 14 10:14 100
-rw-rw-r-- 1 s1855106 s1855106 0 Apr 14 10:14 101
-rw-rw-r-- 1 s1855106 s1855106 0 Apr 14 10:14 102
-rw-rw-r-- 1 s1855106 s1855106 0 Apr 14 10:14 103
-rw-rw-r-- 1 s1855106 s1855106 0 Apr 14 10:14 104
-rw-rw-r-- 1 s1855106 s1855106 0 Apr 14 10:14 105
-rw-rw-r-- 1 s1855106 s1855106 0 Apr 14 10:14 106
ls: write error: Broken pipe

ls?(trap '' PIPE; ls -l | head)will reliably reproduce your issue). You can see the signal disposition of yourbashshell with the builtintrap -pls -l | headworks as expected - could be something to do with your shell (bash v5?) or your ls command (gnu ls?) ?