我是靠谱客的博主 烂漫雨,最近开发中收集的这篇文章主要介绍linux 展示目录结构,展示linux/unix目录文件结构,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#!/bin/sh## tree.sh# A tool that display the dictionary structure in dos's# tree command style.##      __@#  _ ## Tested on slackware, openbsd, netbsd, freebsd.## Just for fun.## The name of the ls program, please use# the absolute path, otherwise, there# may be get some strange errors.#LSPROG="/bin/ls"# COLOR DEFINE# ============#DIR="33[01;34m"EXE="33[01;32m"DEV="33[01;33m"LNK="33[01;36m"ZIP="33[01;31m"SOCK="33[01;35m"NULL="33[00m"ROOT=${1:-.}TRUE=0FALSE=1LAYERS=0FILECOUNT=0DIRCOUNT=0# print_dash# ==========# Print the structure lines#print_dash(){local i=0local num=$1while [ $i -lt $num ]; do  echo -n "|"  for j in 1 2 3; do   echo -n " "  done  i=`expr $i + 1`doneecho -n "|-- "}# ispkg# =====# Test if the file is a package like:# .gz .tar .tgz .tar.gz .zip .rar .rpm# and etc.#ispkg(){local f=$1local i# Package extension list, you can add your coustom# extensions in it.#local pkg__ext=".gz .tar .tgz .tar.gz .zip .rar .rpm"# if the file's suffix contain any package extension# then cut it.for i in $pkg__ext; do  f=${f%$i}doneif [ "$f" != "$1" ]; then  return $TRUEelse  return $FALSEfi}# mktree# ======# The main function, that print the# dictionary structure in dos's tree# command style. It's runs in nesting.#mktree(){local ffor f in `$LSPROG -1 $1 2> /dev/null`; do  f=${f%/}  f=${f##*/}  # If dictionary then print it and enter  # the nesting block.  if [ -d $1/$f ]; then   print_dash $LAYERS   echo -e "${DIR}$f${NULL}"   DIRCOUNT=`expr $DIRCOUNT + 1`   LAYERS=`expr $LAYERS + 1`   mktree $1/$f  else   print_dash $LAYERS   # file is a symbol link   if [ -L $1/$f ]; then    echo -e "${LNK}$f${NULL}"   # file is executable   elif [ -x $1/$f ]; then    echo -e "${EXE}$f${NULL}"   # file is a device   elif [ -c $1/$f -o -b $1/$f ]; then    echo -e "${DEV}$f${NULL}"   # file is a socket   elif [ -S $1/$f ]; then    echo -e "${SOCK}$f${NULL}"   # file is a package   elif `ispkg $f`; then    echo -e "${ZIP}$f${NULL}"   else    echo -e "$f"   fi      FILECOUNT=`expr $FILECOUNT + 1`  fidoneLAYERS=`expr $LAYERS - 1`}echo $ROOTif [ "$1"X != "X" ]; thenmktree $1 #mktree $ROOTelsemktree $ROOTfiecho "`" echo -e "${DIR}$DIRCOUNT${NULL} directories, ${DEV}$FILECOUNT${NULL} files"

阅读(784) | 评论(0) | 转发(0) |

最后

以上就是烂漫雨为你收集整理的linux 展示目录结构,展示linux/unix目录文件结构的全部内容,希望文章能够帮你解决linux 展示目录结构,展示linux/unix目录文件结构所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部