我想要一个Linux命令以树的形式打印目录和文件结构,可能在每个文件之前使用Unicode图标,并提示在Markdown文档中包含输出的最佳语法,行之间没有空格。
例子:
.
├── _config.yml
├── _drafts
│ ├── begin-with-the-crazy-ideas. Textile
│ └── on-simplicity-in-technology. Markdown
├── _includes
│ ├── footer.html
│ └── header.html
├── _layouts
│ ├── default.html
│ └── post.html
├── _posts
│ ├── 2007-10-29-why-every-programmer-should-play-nethack.textile
│ └── 2009-04-26-barcamp-boston-4-roundup.textile
├── _data
│ └── members.yml
├── _site
└── index.html
我为我的Dropbox文件列表编写了这个脚本。
Sed用于删除符号链接文件/文件夹路径在->之后的完整路径
不幸的是,标签丢失了。使用zsh,我能够保存制表符。
! / usr / bin / env bash
#!/usr/bin/env zsh
F1='index-2.md' #With hyperlinks
F2='index.md'
if [ -e $F1 ];then
rm $F1
fi
if [ -e $F2 ];then
rm $F2
fi
DATA=`tree --dirsfirst -t -Rl --noreport | \
sed 's/->.*$//g'` # Remove symlink adress and ->
echo -e '```\n' ${DATA} '\n```' > $F1 # Markdown needs triple back ticks for <pre>
# With the power of piping, creating HTML tree than pipe it
# to html2markdown program, creates cool markdown file with hyperlinks.
DATA=`tree --dirsfirst -t -Rl --noreport -H http://guneysu.pancakeapps.com`
echo $DATA | \
sed 's/\r\r/\n/g' | \
html2markdown | \
sed '/^\s*$/d' | \
sed 's/\# Directory Tree//g' | \
> $F2
输出如下:
```
.
├── 2013
│ └── index.markdown
├── 2014
│ └── index.markdown
├── 2015
│ └── index.markdown
├── _posts
│ └── 2014-12-27-2014-yili-degerlendirmesi.markdown
├── _stash
└── update.sh
```
[BASE_URL/](BASE_URL/)
├── [2013](BASE_URL/2013/)
│ └── [index.markdown](BASE_URL/2013/index.markdown)
├── [2014](BASE_URL/2014/)
│ └── [index.markdown](BASE_URL/2014/index.markdown)
├── [2015](BASE_URL/2015/)
│ └── [index.markdown](BASE_URL/2015/index.markdown)
├── [_posts](BASE_URL/_posts/)
│ └── [2014-12-27-2014-yili-degerlendirmesi.markdown](_posts/2014-12-27-2014-yili-degerlendirmesi.markdown)
├── [_stash](BASE_URL/_stash/)
├── [index-2.md](BASE_URL/index-2.md)
└── [update.sh](BASE_URL/update.sh)
* * *
tree v1.6.0 © 1996 - 2011 by Steve Baker and Thomas Moore
HTML output hacked and copyleft © 1998 by Francesc Rocher
Charsets / OS/2 support © 2001 by Kyosuke Tokoro