#!/bin/sh # This program uses recursion to print all files in t directory tree. # Like ls -R except it can be modified to do stuff. # # I plan to add ability to change mode of files with certain file extensions # like .txt or .cpp # if [ $# -lt 3 ]; then echo -e "\n Error: Too few arguments: Usage: \n\n\ $0 starting_dir targ_file_extention octal_mode \n"; exit; fi; function list_dir() { local last_d=$(pwd); echo "---- In list_dir () $1 (from $last_d) ----"; cd $1; local i=0; local fn; for fn in $(ls); do ((i++)); if [ -f $fn ]; then ((t_files++)) echo "$i fn= $fn"; elif [ -d $fn ]; then echo "Recursing to \"$fn\" "; list_dir $fn; else echo "Unrecognized file type"; fi; done; cd $last_d; echo "---- changing back to $last_d ----\n"; } echo "##### Begin: ##### "; tfiles=0; old_d=$(pwd); start_d=$1; if [ -d $start_d ]; then list_dir $start_d; fi; echo "t_files = $t_files"; echo "##### End ##### "; cd $old_d; exit 0; ##################################################################### # recurse_chmod ~/xdir .txt 644