Use o comando find .
foreach file ( * )
find ${file} -name "*.root" > ${file}.txt
end
Considere usar um shell diferente de csh, que está obsoleto há cerca de 20 anos. Use zsh ou bash interativamente, e não use csh para scripts .
Eu preciso listar arquivos na hierarquia do diretório. Para isso eu escrevi o script como
foreach file ( * )
ls ${file}/*/*/*/*/*.root > ${file}.txt
end
Mas para isso eu tenho que saber que no diretório $ {file} existem 4 diretórios. Então, existe alguma maneira pela qual eu possa generalizar este script, de tal forma que eu não precisei ter idéia de quantos subdiretórios estão presentes?
Use o comando find .
foreach file ( * )
find ${file} -name "*.root" > ${file}.txt
end
Considere usar um shell diferente de csh, que está obsoleto há cerca de 20 anos. Use zsh ou bash interativamente, e não use csh para scripts .
Quase todos os csh s encontrados atualmente são tcsh Se você estiver usando tsh 6.18.00 (20120114) ou mais recente, poderá usar ** (verifique com tcsh --version ):
ls "${file}"/**/*.root
Isso só funcionará se a variável globstar estiver definida:
set globstar
Preencha os documentos de tcsh(1) :
The
globstarshell variable can be set to allow**or***as a file glob pattern that matches any string of characters including/, recursively traversing any existing sub-directories. For example,ls **.cwill list all the .c files in the current directory tree. If used by itself, it will match zero or more sub-directories (e.g.ls /usr/include/**/time.hwill list any file namedtime.hin the /usr/include directory tree;ls /usr/include/**time.hwill match any file in the /usr/include directory tree ending intime.h; andls /usr/include/**time**.hwill match any .h file withtimeeither in a subdirectory name or in the filename itself). To prevent problems with recursion, the**glob-pattern will not descend into a symbolic link containing a directory. To override this, use***(+)