【发布时间】:2014-11-25 18:40:34
【问题描述】:
需要 bash 脚本来显示文件
#!/bin/bash
my_ls() {
# save current directory then cd to "$1"
pushd "$1" >/dev/null
# for each non-hidden (i.e. not starting with .) file/directory...
for file in * ; do
# print file/direcotry name if it really exists...
test -e "$file" && echo "$2$file"
# if directory, go down and list directory contents too
test -d "$file" && my_ls "$file" "$2 "
done
# restore directory
popd >/dev/null
}
my_ls
预期输出:
file1
file2
info (directory)
data
stuff (directory)
input
output
scripts (directory)
doit
helper
testinput
jobs
results (directory)
bob
dave
mary
【问题讨论】:
-
我建议使用
find命令并重新格式化其输出。 -
@Jdamian 这正是我需要的
-
file1,file2,jobs 只是文件,我们需要显示(目录下的目录)
-
或者你可以只使用树。
-
如果您知道
find命令,只需开始创建代码并对其进行测试。如果它不起作用,请向我们展示代码及其输出;那么我们将能够为您提供帮助。正如@Celeo 提到的,这不是编码服务。