简体   繁体   中英

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

You can use find :

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

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

使用-exec选项find

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM