lk/basics/tree.md

37 lines
919 B
Markdown
Raw Permalink Normal View History

2023-10-17 17:04:59 +00:00
---
title: "tree"
2024-04-05 23:04:43 +00:00
tags: [ "basics", "tree", "markdown" ]
2023-10-17 17:04:59 +00:00
---
The `tree` utility outputs a full listing of everything in your current directory, and those below.
- Just directories: `tree -d`
- Output colour to `less`: `tree -C --info | less -re`
- Ignore files in the `.gitignore` file: `tree --gitignore`
You can place information about the files in a directory to use with the `tree --info` option, like this:
```
config
Config files.
This is a git submodule.
README.md
Summary of the git.
*.jpg
Little picture, does not display
words well.
```
Each description-line starts with a tab.
2024-04-05 23:04:43 +00:00
## Markdown Conversion
To represent a file structure as a nested series of markdown lists, you can try this horrifying `sed` one-liner:
```bash
tree -tf --dirsfirst --gitignore --noreport --charset ascii | \
sed -e 's/| \+/ /g' \
-e 's/[|`]-\+/ */g' \
-e 's:\(* \)\(\(.*/\)\([^/]\+\)\):\1[\4](\2):g'
```