Loop over files (Bash)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen

This is cool: You can loop over files in a directory and do stuff with it!

Examples

Start simple:

#!/bin/bash

cd ~/images-tmp
for file in *
do
   echo "File name: $file"
done	

Create links to all files in this folder, and put those links in another folder:

for file in *.jpg
do

   source="${PWD}/${file}"
   link="/var/www/media.example.com/tmp2/$file"

   echo "	Path+file: $source - Destination: $link"

   ln -s "$source" "$link"
	
done

Sources