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
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Joozty
  • 460
  • 2
  • 12
  • 40
  • 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,554
  • 1
  • 22
  • 37