Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

50%
+0 −0
Q&A How to list the first x files in each directory

Here's my approach: find l1 -type d \ | while read d; do find $d -maxdepth 1 -type f \ | head -n3; done; If your middle directories also contain files, it will also show them (of course, ...

posted 7mo ago by alx‭  ·  edited 7mo ago by alx‭

Answer
#11: Post edited by user avatar alx‭ · 2023-10-10T11:27:51Z (7 months ago)
remove superfluous sort
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
#10: Post edited by user avatar alx‭ · 2023-10-10T11:27:21Z (7 months ago)
oops; we need to sort before head(1).
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done \
  • | sort;
  • ```
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
#9: Post edited by user avatar alx‭ · 2023-10-10T11:26:17Z (7 months ago)
sort last
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
  • Or you could sort just once after `done`, depending on your needs. It may be faster or slower, depending on what you do with it. Please try both. Also, the order is slightly different for directories that contain both files and other directories.
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done \
  • | sort;
  • ```
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done \
  • | sort;
  • ```
#8: Post edited by user avatar alx‭ · 2023-10-10T10:16:30Z (7 months ago)
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
  • Or you could sort just once after `done`, depending on your needs. It may be faster or slower, depending on what you do with it. Please try both. Also, the sort is slightly different for directories that contain both files and other directories.
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done \
  • | sort;
  • ```
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
  • Or you could sort just once after `done`, depending on your needs. It may be faster or slower, depending on what you do with it. Please try both. Also, the order is slightly different for directories that contain both files and other directories.
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done \
  • | sort;
  • ```
#7: Post edited by user avatar alx‭ · 2023-10-10T10:16:13Z (7 months ago)
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
  • Or you could sort just once after `done`, depending on your needs. It may be faster or slower, depending on what you do with it. Please try both.
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done \
  • | sort;
  • ```
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
  • Or you could sort just once after `done`, depending on your needs. It may be faster or slower, depending on what you do with it. Please try both. Also, the sort is slightly different for directories that contain both files and other directories.
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done \
  • | sort;
  • ```
#6: Post edited by user avatar alx‭ · 2023-10-10T10:15:04Z (7 months ago)
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
  • Or you could sort just once after `done`, depending on your needs. It may be faster or slower, depending on what you do with it. Please try both.
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done \
  • | sort;
  • ```
#5: Post edited by user avatar alx‭ · 2023-10-10T10:12:38Z (7 months ago)
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • This is what it shows for me in a tree similar to yours, where I added files to `l2`:
  • ```sh
  • $ find l1 -type d | while read d; do find $d -maxdepth 1 -type f | head -n3; done;
  • l1/l2/f2
  • l1/l2/f5
  • l1/l2/f4
  • l1/l2/d0/f2
  • l1/l2/d0/f5
  • l1/l2/d0/f4
  • l1/l2/d5/f2
  • l1/l2/d5/f5
  • l1/l2/d5/f4
  • l1/l2/d4/f2
  • l1/l2/d4/f5
  • l1/l2/d4/f4
  • l1/l2/d2/f2
  • l1/l2/d2/f5
  • l1/l2/d2/f4
  • l1/l2/d1/f2
  • l1/l2/d1/f5
  • l1/l2/d1/f4
  • l1/l2/d3/f2
  • l1/l2/d3/f5
  • l1/l2/d3/f4
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
#4: Post edited by user avatar alx‭ · 2023-10-10T10:08:43Z (7 months ago)
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If your middle directories also contain files, it will also show them (of course, only the first 3).
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
#3: Post edited by user avatar alx‭ · 2023-10-10T10:07:53Z (7 months ago)
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • sort \
  • | head -n3;
  • done;
  • ```
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • | sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | sort \
  • | head -n3;
  • done;
  • ```
#2: Post edited by user avatar alx‭ · 2023-10-10T10:07:30Z (7 months ago)
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria <https://serverfault.com/questions/181787/find-command-default-sorting-order>:
  • ```sh
  • find l1 -type d \
  • sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • sort \
  • | head -n3;
  • done;
  • ```
  • Here's my approach:
  • ```sh
  • find l1 -type d \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • | head -n3;
  • done;
  • ```
  • If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria (see <https://serverfault.com/questions/181787/find-command-default-sorting-order>):
  • ```sh
  • find l1 -type d \
  • sort \
  • | while read d; do
  • find $d -maxdepth 1 -type f \
  • sort \
  • | head -n3;
  • done;
  • ```
#1: Initial revision by user avatar alx‭ · 2023-10-10T10:06:57Z (7 months ago)
Here's my approach:

```sh
find l1 -type d \
| while read d; do
	find $d -maxdepth 1 -type f \
	| head -n3;
done;
```

If you want the first 3 files in a certain order, you'll need to sort(1) them according to your needs; otherwise, you'll get the first three files according to find(1)'s default criteria <https://serverfault.com/questions/181787/find-command-default-sorting-order>:

```sh
find l1 -type d \
sort \
| while read d; do
	find $d -maxdepth 1 -type f \
	sort \
	| head -n3;
done;
```