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="\033[01;34m"EXE="\033[01;32m"DEV="\033[01;33m"LNK="\033[01;36m"ZIP="\033[01;31m"SOCK="\033[01;35m"NULL="\033[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) |

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值