user2967825
user2967825

Reputation: 13

Run script against all txt files in directory and sub directories - BASH

What im trying to do is something along the lines of(this is pseudocode):

for txt in  $(some fancy command ./*.txt); do
some command here $txt

Upvotes: 1

Views: 5515

Answers (3)

Florian Feldhaus
Florian Feldhaus

Reputation: 5932

Try

find . | grep ".txt" | xargs -I script.sh {}

find returns all files in the directory. grep selects only .txt files and xargs sends the file as Parameter to script.sh

Upvotes: 0

Barmar
Barmar

Reputation: 781761

Use the -exec option to find:

find /usr/share/wordlists/*/* -type f -name '*.txt' -exec yourScript {} \;

Upvotes: 0

devnull
devnull

Reputation: 123608

You can use find:

find /path -type f -name "*.txt" | while read txt; do
  echo "$txt";   # Do something else
done

Upvotes: 5

Related Questions