This is an old revision of the document!


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.1220905649.txt.gz · Last modified: 2013/09/19 16:42 (external edit)
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0