How to Recursively Find All Files in Current and Subfolders Based on Wildcard Matching

How can I recursively find all files in current and subfolders based on wildcard matching?

Use find:

find . -name "foo*"

find needs a starting point, so the . (dot) points to the current directory.

How can I recursively find all files in current and subfolders based on regular expressions

To match whole paths that end in a filename matching a given regular expression, you could prepend .*/ to it, for example .*/f.+1$. The .*/ should match the path preceding the filename.

Bash - What is a good way to recursively find the type of all files in a directory and its subdirectories?

This may help: How to recursively list subdirectories in Bash without using "find" or "ls" commands?

That said, I modified it to accept user input as follows:

#!/bin/bash

recurse() {
for i in "$1"/*;do
if [ -d "$i" ];then
echo "dir: $i"
recurse "$i"
elif [ -f "$i" ]; then
echo "file: $i"
fi
done
}

recurse $1

If you didn't want the files portion (which it appears you don't) then just remove the elif and line below it. I left it in as the original post had it also. Hope this helps.

Find all files matching pattern in directory and copy subdirectories and files found

You might want to use rsync instead of find:

rsync -amv --include='*/' --include='*.xml' --exclude='*' "$DIRECTORY"/ "$OUTPUT_DIRECTORY"

How to ls all the files in the subdirectories using wildcard?

3 solutions :

Simple glob

ls */*.pdb

Recursive using bash

shopt -s globstar
ls **/*.pdb

Recursive using find

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


Related Topics



Leave a reply



Submit