codyc4321
codyc4321

Reputation: 9682

bash equivalent for os.walk?

I am using 2to3 to fix my script library, and it seems to be a command line thing, not a shell thing.

I want to do all files from /home/me/scripts downward, assuming they end in .py. Is there an easy way to do 2to3 -y filename for each file under my folder in the shell?

Upvotes: 2

Views: 2270

Answers (2)

chepner
chepner

Reputation: 532023

bash 4 provides a way of doing recursive globbing.

shopt -s globstar
2to3 /home/me/scripts/**/*.py

Upvotes: 4

kfx
kfx

Reputation: 8537

There's find command:

 find /home/me/scripts  -iname "*.py" -exec 2to3 {} \;

The -exec argument tell it to execute the command that follows after this argument, which is 2to3 {} in this case. For each file found, {} is replaced by the name of that file.

Upvotes: 4

Related Questions