Wednesday, December 15, 2010

How to enumerate files and directories in Bash script

Enumerate files:

for file in /Users/$USER/*; do
        if [ -f "$file" ]; then
            echo $file
        fi
done

Enumerate directories:

for file in /usr/*; do
        if [ -d "$file" ]; then
            echo $file
        fi
done

No comments:

Post a Comment