#! /bin/bash # Place this script in a directory containing many directories, say dir1, dir2, .... # This script goes into each directory removing all *.txt files with exception of "param.txt". # Warning: If there exist any subfolders in dir1, dir2,..., all the *.txt files in it will also be removed. # The script only removes non-'param.txt' *.txt files that has no white space in the file names. E.g., the files para (2).txt will not be removed. for dir in *; do cp -p $dir/'param.txt' $dir/'param.temp' done find . -type f -name '*.txt' -print| while read obj3 do echo 'removing' $obj3 rm $obj3 done for dir in *; do cp -p $dir/'param.temp' $dir/'param.txt' rm $dir/'param.temp' done # end script