bash foreach File in Directory

Posted:

How to Iterate over All Files in a Directory

This works on my MacBook, running Mac OSX Snow Leopard (10.6). Unix.

To list all files in your Documents folder, for example, enter in Terminal (Mac's command-line):

for file in ~/Documents/*; do echo "$file"; done

To create hardlinks in the present working directory that point to files in your Documents folder, enter:

for file in ~/Documents/*; do ln "$file"; done