10

I have the following directory structure:

bocoup_data/
├── text_reuse
│   └── v2
│       └── json
│           ├── alignments
│           └── texts
└── topic_modelling
    └── v2
        └── json

I'd like to be able to show a subset of the files in those directories, because some of the directories pictured above have thousands of files. Is there a way to show only the first n files from each directory when calling the tree command in Ubuntu?

kos
  • 35,535
  • 13
  • 101
  • 151
duhaime
  • 608
  • 1
  • 7
  • 13
  • 2
    Please don't post screenshots of text. Just paste the text directloy and apply code formatting. – muru Oct 17 '15 at 00:50
  • 1
    Sorry @muru, I had blown away the directory but had the image. I'm not sure why the text is more valuable than the image in this case, but I'll use text instead. – duhaime Oct 17 '15 at 12:42

2 Answers2

5

tree as such does not have any options for this, but you can prevent it from printing files for directories with more than n entries:

$ tree /usr --filelimit 10
/usr
├── bin [3260 entries exceeds filelimit, not opening dir]
├── include [1110 entries exceeds filelimit, not opening dir]
├── lib [3700 entries exceeds filelimit, not opening dir]
├── lib32 [610 entries exceeds filelimit, not opening dir]
├── lib64 -> lib
├── local
│   ├── bin
│   │   ├── gpg1v -> /usr/bin/gpgv
│   │   └── vless
│   ├── etc
│   ├── games
│   ├── include
│   ├── lib
│   ├── man
│   ├── sbin
│   ├── share
│   │   └── man -> ../man
│   └── src
├── sbin -> bin
├── share [243 entries exceeds filelimit, not opening dir]
└── src

19 directories, 2 files
muru
  • 193,181
  • 53
  • 473
  • 722
  • Thanks @muru; this is close to what I am after, but I would like to show n files from those directories that have more than n files as well. – duhaime Oct 17 '15 at 12:43
  • 1
    For anybody looking to display the directories only, use [`tree /usr -d`](https://askubuntu.com/a/431257/775359) – Nagabhushan S N May 18 '20 at 08:47
0

The find shell command has options to limit output to files of certain max age only. This might help you.

Roland
  • 184
  • 1
  • 11