Skip to content

Instantly share code, notes, and snippets.

@TTy32
Created February 12, 2025 10:44
Show Gist options
  • Save TTy32/4b66351dde364af54b01ca7a4dd7df02 to your computer and use it in GitHub Desktop.
Save TTy32/4b66351dde364af54b01ca7a4dd7df02 to your computer and use it in GitHub Desktop.
tree: limit number of files for each directory
tree -L 3 | awk '
BEGIN {
last_prefix = ""
count = 1
}
{
# Extract indentation
prefix = $0
sub(/[^│├└─]+$/, "", prefix)
if (count < 5) {
print
}
if (prefix == last_prefix) {
count++
} else {
if (count > 5) {
print prefix " " count " more files..."
}
count = 1
}
last_prefix = prefix
}'
@TTy32
Copy link
Author

TTy32 commented Feb 12, 2025

Produces:

├── venv-metal
│   ├── bin
│   │   ├── Activate.ps1
│   │   ├── activate
│   │   ├── activate.csh
│   │   ├── activate.fish
│   │   ├── estimator_ckpt_converter
│   │   └── 28 more files...              <<<<<<<<<<<
│   ├── include
│   │   └── python3.11
│   ├── lib
│   │   └── python3.11
│   └── pyvenv.cfg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment