Shell实现 1、find命令 find dir.yahoo.com/ -name '*.html' | less 2、for加if foreach_dir(){ for file in $1/* do if [ -d $file ]; then foreach_dir $file else #do something here fi done } Python实现 import os def listalldir(path,level=0): for i in os.listdir(path): print ' '*(level+1) + i file = path + os.path.sep + i if os.path.isdir(file): listalldir(file,level+1) rootpath = os.path.abspath('.') print rootpath listalldir(rootpath)