for loop over specific files in a directory using Bash for loop over specific files in a directory using Bash bash bash

for loop over specific files in a directory using Bash


#!/bin/bashFILES=/home/shep/Desktop/test/*for f in $FILESdoif [[ "$f" != *\.* ]]then  DO STUFFfidone


If you want it a little bit more complex, you can use the find-command.

For the current directory:

for i in `find . -type f -regex \.\\/[A-Za-z0-9]*`doWHAT U WANT DONEdone

explanation:

find . -> starts find in the current dir-type f -> find only files-regex -> use a regular expression\.\\/[A-Za-z0-9]* -> thats the expression, this matches all files which starts with ./(because we start in the current dir all files starts with this) and has only charsand numbers in the filename.

http://infofreund.de/bash-loop-through-files/


You can use negative wildcards? to filter them out:

$ ls -1a.txtb.txtc.pngd.py$ ls -1 !(*.txt)c.pngd.py$ ls -1 !(*.txt|*.py)c.png