0

How can I stop script when command "find" gets to a folder with permission denied.

I make a list of all folders in my PC.

I would like to stop the searching process when "find" finds a permission denied folder.

DIRS=$(find . -type d)

Thanks a lot

Martijn Pieters
  • 963,270
  • 265
  • 3,804
  • 3,187
Joozty
  • 390
  • 11
  • 33
  • Please look at [this answered question](http://unix.stackexchange.com/questions/225572/exit-bash-when-find-gets-to-a-folder-with-permission-denied) or [this one](http://stackoverflow.com/questions/3474526/stop-on-first-error). – Tym Mar 27 '16 at 18:19

1 Answers1

0

Can't test this now, but you should check with exec if the folder is executable.

Something like

find -type d -print0 -not -exec test -x '{}' \; -quit
xvan
  • 4,281
  • 1
  • 18
  • 35