Shell脚本生成目录树结构文本文件 -- Snippets

本文介绍了一个使用Bash编写的脚本,该脚本能生成目录树状结构的文本文件,支持中文和包含空格的目录名。脚本提供了多个选项,如输出到文件、禁止屏幕输出等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

不管出于什么目的, 本脚本的作用生成目录树状结构文本文件, 支持中文和有空格等的文件目录名. 比如
$./gdt.sh /cygdrive/e/ccccc -o
将/cygdrive/e/ccccc目录树状结构文本文件ccccc.txt. 如果不带目录名参数, 则生成当前目录树状结构.

本脚本完成使用Bash编程, 并且未使用sed, awk等.

具体用法和选项含意可使用-h显示简单帮助, 或见文章结尾源代码:
$./gdt.sh -h

用法说明如下:
usage: gdt.sh [-h] [-o [file name]] [-n] [directory]
Generate directory tree.
|-- for file, /-- for empty directory, +-- for non-empty directory.

Options:
-h help page, any other options ignored
-o output results to a file, no file name follwed means output file has a name same as directory.
-n no screen output, if no file specificed, it redirects to /dev/null
All extra arguments will be ignored automatically.
Only the first directory will be considered if more exist.

gdt源代码及生成文件样本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值