How to go to each directory and execute a command?

后端 未结 10 998
無奈伤痛
無奈伤痛 2020-12-02 04:13

How do I write a bash script that goes through each directory inside a parent_directory and executes a command in each directory

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 04:23

    This answer posted by Todd helped me.

    find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && pwd" \;
    

    The \( ! -name . \) avoids executing the command in current directory.

提交回复
热议问题