with - linux find-exec{}

Recursively look for files with a specific extension (6)

I'm trying to find all files with a specific extension in a directory and its subdirectories with my bash (Latest Ubuntu LTS Release).

This is what's written in a script file:



browsefolders ()
  for i in "$1"/*; 
    echo "dir :$directory"
    echo "filename: $i"
    #   echo ${i#*.}
    extension=`echo "$i" | cut -d'.' -f2`
    echo "Erweiterung $extension"
    if     [ -f "$i" ]; then        

        if [ $extension == $suffix ]; then
            echo "$i ends with $in"

            echo "$i does NOT end with $in"
    elif [ -d "$i" ]; then  
    browsefolders "$i"
browsefolders  "$directory"

Unfortunately, when I start this script in terminal, it says:

[: 29: in: unexpected operator

(with $extension instead of 'in')

What's going on here, where's the error? But this curly brace

  1. There's a { missing after browsefolders ()
  2. All $in should be $suffix
  3. The line with cut gets you only the middle part of front.middle.extension. You should read up your shell manual on ${varname%%pattern} and friends.

I assume you do this as an exercise in shell scripting, otherwise the find solution already proposed is the way to go.

To check for proper shell syntax, without running a script, use sh -n scriptname.

The syntax I use is a bit different than what @Matt suggested:

find $directory -type f -name \*.in

(it's one less keystroke).

To find all the pom.xml files in your current directory and print them, you can use:

find . -name 'pom.xml' -print

Without using find:

du -a $directory | awk '{print $2}' | grep '\.in$'

find $directory -type f -name "*.in"|grep $substring

find {directory} -type f -name '*.extension'

example to find all csv files in the current directory and its sub-directories

find . -type f -name '*.csv'