/dev/nu-6ren">
sách gpt4 ai đã đi

linux - Bash 脚本 Shell 脚本

In lại 作者:太空宇宙 更新时间:2023-11-04 06:03:34 28 4
mua khóa gpt4 Nike

需要bash脚本来显示文件

#!/thùng/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 "
xong
# restore directory
popd >/dev/null
}

my_ls

预期输出:

file1
file2
info (directory)
dữ liệu
stuff (directory)
đầu vào
đầu ra
scripts (directory)
doit
người giúp việc
testinput
jobs
results (directory)
bob
dave
mary

1 Câu trả lời

这是一个 bash 脚本,可以满足您的要求。

$ cat tree
#!/thùng/bash
# tree [DIR]

ls_tree() {
dir="${1:-.}"
while read name ; do
if [[ -n "$name" ]]; then
if [[ "$name" =~ :$ ]]; then
dir="${name%:}"
khác
echo "$dir/${name%*}"


xong
}

show_tree() {
sed -e 's|^./||' | sort | sed -e 's|/$||' -e 's|[^/]*/| |g'
}


/bin/ls -1RF "${1:-.}" | ls_tree "${1:-.}" | show_tree

这是一个示例输出:

$ tree
fun.rb
fun
dữ liệu
filter.awk
good
inputtest.sh
reqs
test1.awk
đầu vào
pairs
pairs.sh
split-collections
indir
col1
col2
col3
outdir
file1
file2
file21
file22
file23
file3
file31
file32
file33
split-collections.sh
t1
tree1

关于linux - Bash 脚本 Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27134250/

28 4 0
Bài viết được đề xuất: php - 多少kb有一个mb,有人说1000,有人说1024
Bài viết được đề xuất: c - 需要帮助来理解我程序中的缺陷
Bài viết được đề xuất: c - 关闭标准输出时的奇怪行为
Bài viết được đề xuất: Linux 循环运行一个又一个脚本
太空宇宙
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com