Encontre arquivos excluindo alguns diretórios

Encontre arquivos excluindo alguns diretórios

Estou trabalhando com a seguinte estrutura de diretórios:

onathan@Aristotle:~/EclipseWorkspaces/ShellUtilities/ShellUtilities$ ls -R
.:
calculateTargetDay  CustomizeIso  ec  makeExecutable  Models  modifyElementList  Sourced  test file  Testing  valrelease

./Models:
testcase

./Sourced:
colors  stddefs  stdFunctions  SupportTesting

./Testing:
test  testCalculateTargetDay  testColors  testModifyElementList  testStddefs  testStdFunctions  testSupportTesting  tst

O que eu quero fazer é executar um comando em todos os arquivos no diretório de nível superior e no diretórioTeste. Não quero executar o comando nos arquivos dos diretóriosOrigemeModelos. Para fazer isso executei o seguinte comando:

find . -name Sourced -prune -name Models -prune ! -name '\.*'  -execdir echo '{}' \;

Este exemplo não executou o comando em nenhum dos arquivos na estrutura de diretórios.

Quando executei o seguinte comando na mesma estrutura de diretórios:

find . ! -name '\.*'  -execdir echo '{}' \;

Eu obtive o seguinte resultado

./calculateTargetDay
./CustomizeIso
./Testing
./testModifyElementList
./test
./testColors
./testStdFunctions
./testCalculateTargetDay
./testStddefs
./testSupportTesting
./tst
./test file
./modifyElementList
./ec
./Sourced
./stdFunctions
./stddefs
./SupportTesting
./colors
./valrelease
./Models
./testcase
./makeExecutable

Como você pode ver, posso executar um comando na árvore de diretórios e aplicá-lo a todos os arquivos ou posso tentar ser seletivo e acabar executando em nenhum arquivo. Como posso obter a aplicação seletiva de um comando que necessito?

Responder1

Você pode fazer isso com Regex, no diretório pai:

find . -type f -regextype posix-egrep -regex '\./([^/]+|Testing/.*)$'

\./([^/]+|Testing/.*)$encontrará todos os arquivos ( -type f) no diretório atual e Testingsomente no diretório.

Para executar um comando, adicione -execuma ação:

find . -type f -regextype posix-egrep -regex '\./([^/]+|Testing/.*)$' -exec echo {} \;

Substitua echopelo seu comando real.

Exemplo:

$ find . -type f                                                                           
./foo
./Sourced/src
./Testing/test
./bar
./spam
./Models/model

$ find . -type f -regextype posix-egrep -regex '\./([^/]+|Testing/.*)$'                 
./foo
./Testing/test
./bar
./spam

$ find . -type f -regextype posix-egrep -regex '\./([^/]+|Testing/.*)$' -exec echo {} \;
./foo
./Testing/test
./bar
./spam

informação relacionada