Shell

Do something recursively on all files

#!/bin/sh
 
function search_dir()
{
    DIR=$1;
 
    for file in $DIR/*; do
        if [[ -f $file ]]; then
            echo "Do something with $file"
        fi;
    done
 
 
    for element in $DIR/* ; do
        if [[ -e $element && -d $element && \
            $(basename "$element") != ".." && \
            $(basename "$element") != "." ]]; then
 
            search_dir "$element";
        fi;
    done;
}
 
search_dir "."
linux/shell.txt · Last modified: 2013/09/19 16:40 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki