Why am I able to cat a directory?

Marc Fournier scrappy at hub.org
Sun Jan 22 14:44:27 PST 2023


Simplistically, a directory is just a file with binary data in it ... 
you can manipulate it in the same way as any other file ... I tend to 
write perl scripts that open a directory, read the contents ( files ) 
and then manipulate the files within it:

--
$handle = opendir( $shifts_directory );

   if ($handle) {
     $arrFiles = array();
     while (($entry = readdir($handle)) !== FALSE) {
       if ($entry != "." && $entry != "..") {
         $arrFiles[] = $entry;
       }
     }
   } else {
     exit ( 'directory does not exist: ' . $shifts_directory );
   }

   closedir($handle);
--

Using cat isn't very effective, but as effective as using cat to view an 
image file, or excel spreadsheet ...


On 2023-01-22 10:37, Stanislav Syekirin wrote:
> Hi all,
>
> I accidentally noticed that the following runs without error (even 
> though it only outputs some binary data I can't understand) on my 
> Dragonfly 6.2 install:
>
>     mkdir a
>     cat a
>
> The same happens on NetBSD, so it probably isn't a bug, but I really 
> can't imagine the intended use case. Can someone please explain?
>
> Regards
> Stanislav



More information about the Users mailing list