How to exclude a directory in find . command

后端 未结 30 1360
醉酒成梦
醉酒成梦 2020-11-22 03:36

I\'m trying to run a find command for all JavaScript files, but how do I exclude a specific directory?

Here is the find code we\'re using.<

30条回答
  •  终归单人心
    2020-11-22 04:15

    For what I needed it worked like this, finding landscape.jpg in all server starting from root and excluding the search in /var directory:

    find / -maxdepth 1 -type d | grep -v /var | xargs -I '{}' find '{}' -name landscape.jpg

    find / -maxdepth 1 -type d lists all directories in /

    grep -v /var excludes `/var' from the list

    xargs -I '{}' find '{}' -name landscape.jpg execute any command, like find with each directory/result from list

提交回复
热议问题