diff --git a/bin/php/ezcache.php b/bin/php/ezcache.php
index 3832162..f4e9e3b 100755
--- a/bin/php/ezcache.php
+++ b/bin/php/ezcache.php
@@ -158,9 +158,40 @@ if ( $options['list-ids'] )
 
 function clearItems( $cacheEntries, $cli, $name )
 {
-    if ( $name )
-        $name = $cli->stylize( 'emphasize', $name );
-    $cli->output( 'Clearing ' . $name . ': ', false );
+    if ( !$name )
+        $name = 'All cache';
+    $name = $cli->stylize( 'emphasize', $name );
+    $cli->output( 'Clearing ' . $name . ': ' );
+
+    $warnPaths = array();
+    foreach ( $cacheEntries as $cacheEntry )
+    {
+        $absPath = realpath( eZSys::cacheDirectory() . DIRECTORY_SEPARATOR . $cacheEntry['path'] );
+        // Warn if the cache entry is not function based, and the path is outside ezp root, and the path has less than 2 elements
+        if ( $absPath &&
+             !isset( $cacheEntry['function'] ) &&
+             strpos( dirname( $absPath ) . DIRECTORY_SEPARATOR, realpath( eZSys::rootDir() ) . DIRECTORY_SEPARATOR ) === false &&
+             count( explode( DIRECTORY_SEPARATOR, $absPath ) ) < 3 ) // 3, since one path element ('/foo') produces two exploded elements
+        {
+            $warnPaths[] = $absPath;
+        }
+    }
+
+    if ( count( $warnPaths ) > 0 )
+    {
+        $cli->warning( 'The following cache paths are outside of the eZ Publish root directory, and have less than 2 path elements. Are you sure you want to clear them?' );
+        foreach ( $warnPaths as $warnPath )
+        {
+            $cli->output( $warnPath );
+        }
+        $input = getUserInput( 'Clear? yes/no:', array( 'yes', 'no' ) );
+
+        if ( $input == 'no' )
+        {
+            return;
+        }
+    }
+
     $i = 0;
     foreach ( $cacheEntries as $cacheEntry )
     {
@@ -176,9 +207,41 @@ function clearItems( $cacheEntries, $cli, $name )
 function purgeItems( $cacheEntries, $cli, $name )
 {
     global $purgeSleep, $purgeMax, $purgeExpiry;
-    if ( $name )
-        $name = $cli->stylize( 'emphasize', $name );
-    $cli->output( 'Purging ' . $name . ': ', false );
+    if ( !$name )
+        $name = 'All cache';
+    $name = $cli->stylize( 'emphasize', $name );
+    $cli->output( 'Purging ' . $name . ': ' );
+
+    $warnPaths = array();
+    foreach ( $cacheEntries as $cacheEntry )
+    {
+        $absPath = realpath( eZSys::cacheDirectory() . DIRECTORY_SEPARATOR . $cacheEntry['path'] );
+        // Warn if the cache entry is not function based, and the path is outside ezp root, and the path has less than 2 elements
+        if ( $absPath &&
+             !isset( $cacheEntry['purge-function'] ) &&
+             !isset( $cacheEntry['function'] ) &&
+             strpos( dirname( $absPath ) . DIRECTORY_SEPARATOR, realpath( eZSys::rootDir() ) . DIRECTORY_SEPARATOR ) === false &&
+             count( explode( DIRECTORY_SEPARATOR, $absPath ) ) < 3 ) // 3, since one path element ('/foo') produces two exploded elements
+        {
+            $warnPaths[] = $absPath;
+        }
+    }
+
+    if ( count( $warnPaths ) > 0 )
+    {
+        $cli->warning( 'The following cache paths are outside of the eZ Publish root directory, and have less than 2 path elements. Are you sure you want to purge them?' );
+        foreach ( $warnPaths as $warnPath )
+        {
+            $cli->output( $warnPath );
+        }
+        $input = getUserInput( 'Purge? yes/no:', array( 'yes', 'no' ) );
+
+        if ( $input == 'no' )
+        {
+            return;
+        }
+    }
+
     $i = 0;
     foreach ( $cacheEntries as $cacheEntry )
     {
@@ -188,9 +251,37 @@ function purgeItems( $cacheEntries, $cli, $name )
         eZCache::clearItem( $cacheEntry, true, 'reportProgress', $purgeSleep, $purgeMax, $purgeExpiry );
         ++$i;
     }
+
     $cli->output();
 }
 
+if ( !function_exists( 'readline' ) )
+{
+    function readline( $prompt = '' )
+        {
+            echo $prompt . ' ';
+            return trim( fgets( STDIN ) );
+        }
+}
+
+if ( !function_exists( 'getUserInput' ) )
+{
+    function getUserInput( $query, $acceptValues )
+    {
+        $validInput = false;
+        while( !$validInput )
+        {
+            $input = readline( $query );
+            if ( $acceptValues === false ||
+                 in_array( $input, $acceptValues ) )
+            {
+                $validInput = true;
+            }
+        }
+        return $input;
+    }
+}
+
 function reportProgress( $filename, $count )
 {
     global $cli;
