Pergunta

Good morning !

This is a simple one I believe, but I am still a noob :)

I am trying to find all folders with a certain name. I am able to do this with the command

find /path/to/look/in/ -type d | grep .texturedata

The output gives me lots of folders like this :

/path/to/look/in/.texturedata/v037/animBMP

But I would like it to stop at .texturedata :

/path/to/look/in/.texturedata/

I have hundreds of these paths and would like to lock them down by piping the output of grep into chmod 000

I was given a command with the argument -dpe once, but I have no idea what it does and the Internet has not be able to help me determine it's usage

Thanks you very much for your help !

Foi útil?

Solução

I am trying to find all folders with a certain name. I am able to do this with the command find /path/to/look/in/ -type d | grep .texturedata

No need to grep output of find to look for specific directory name. -name option of find will do the same job.

find /path/to/look/in/ -type d -name '.texturedata'

I would like it to stop at .texturedata

-prune option is quite suitable for this requirement

find /path/to/look/in/ -type d -name '.texturedata' -prune

I have hundreds of these paths and would like to lock them down by piping the output of grep into chmod 000

Try using find with -exec option

find /path/to/look/in/ -type d -name '.texturedata' -exec chmod 000 {} \; -prune

More efficient approach would be to pipe output of find using xargs

find /path/to/look/in/ -type d -name '.texturedata' -prune -print0 | xargs -0 chmod 000

TEST

$ tree -pa
.
|-- [drwxrwxrwx]  .texturedata
|   `-- [drwxrwxrwx]  .texturedata
|-- [drwxrwxrwx]  dir1
|   |-- [drwxrwxrwx]  .texturedata
|   |   `-- [-rwxrwxrwx]  file2
|   `-- [drwxrwxrwx]  dir11
|       `-- [-rwxrwxrwx]  file111
|-- [drwxrwxrwx]  dir2
|   `-- [drwxrwxrwx]  .texturedata
|       `-- [-rwxrwxrwx]  file3
|-- [drwxrwxrwx]  dir3
|   `-- [-rwxrwxrwx]  file4
`-- [-rwxrwxrwx]  file1

8 directories, 5 files
$ find . -type d -name '.texturedata' -prune -print0 | xargs -0 chmod 000
$ tree -pa
.
|-- [d---------]  .texturedata [error opening dir]
|-- [drwxrwxrwx]  dir1
|   |-- [d---------]  .texturedata [error opening dir]
|   `-- [drwxrwxrwx]  dir11
|       `-- [-rwxrwxrwx]  file111
|-- [drwxrwxrwx]  dir2
|   `-- [d---------]  .texturedata [error opening dir]
|-- [drwxrwxrwx]  dir3
|   `-- [-rwxrwxrwx]  file4
`-- [-rwxrwxrwx]  file1

7 directories, 3 files

Outras dicas

Try

find /path/to/look/in/ -type d -name .texturedata -print0 | xargs -0 chmod 000

or

find /path/to/look/in/ -type d -name .texturedata -exec chmod 000 {} \;

No need to use grep. The above will only change the permissions of .texturedata, not its children, provided no directory in .texturedata is also named .texturedata. And it will find all .texturedata inside /path/to/look/in.

You can use -quit option in gnu find with -exec:

find /path/to/look/in/ -type d -name ".texturedata" -exec chmod 000 '{}' \; -quit
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top