Delete a directory on OpenVMS

03-04-2018 | Remy van Elst


Table of Contents


openvms

(You can read all my OpenVMS articles by clicking the picture above)

My OpenVMS adventure continues, in this small item I talk about the removal of folders on OpenVMS. As you might expect, different than on linux.

I tried to set up SSH public key authentication so that I can use my regular SSH key instead of typing my password on the DECUServe system. I found a guide for that in the HPe documentation. That however required the creation of some files and folders and I made a typo in the creation of a folder. Of course I noticed that way too late so there were files in there as well.

As you might have guessed, I went down a different rabbit hole to remove this folder, SSH public key authentication does not work yet. The DECUServe system allows SSH login with a password initially.

If you like this article, consider sponsoring me by trying out a Digital Ocean VPS. With this link you'll get a $5 VPS for 2 months free (as in, you get $10 credit). (referral link)

DIR [.SSH]

The folder I created is named SSH, but it should be named SSH2. This is what's in the folder:

 $ dir [.SSH]

Directory EISNER$DRA3:[DECUSERVE_USER.EXAMPLE.SSH]

AUTHORIZATION.;3    REMY-GATEWAY.PUB;1

Total of 2 files.

OpenVMS seperates folders with the period (.) and they must be enclosed in square brackets. The first period expands to the current folder.

After creating the correct folder (CREATE /DIRECTORY [.SSH2]) and copying the files over:

 $ copy [.SSH]*.*;* [.SSH2]
 $ 

It was time to remove the folder.

rm -rf [.SSH]?

Let's try to apply some logic here. CREATE is the command to create files and folders. So would REMOVE then remove a folder?

 $ REMOVE [.SSH]
%DCL-W-IVVERB, unrecognized command verb - check validity and spelling
 \REMOVE\

Nope, it doesn't. Let's try what we know from *NIX:

 $ RM
_Remote host:
 Interrupt

No clue what that does, but it's not removing my folder. ^C gets me out.

But, OpenVMS has a very extensive HELP system, lets find out what RM does:

RMS

     OpenVMS Record Management Services (RMS) are generalized routines
     that assist user programs in processing and managing files and
     records. 
     [...]

Okay, nice, but not what I was looking for. RMDIR maybe?

 $ RMDIR [.SSH]
%DCL-W-IVVERB, unrecognized command verb - check validity and spelling
 \RMDIR\

Last resort, the Windows BATCH DEL command:

 $ del
_File:
Interrupt

That at least asks for a filename. Let's see if we can get the directory syntax right:

This all failed, syntax wise not the correct format to specify a folder:

$ DEL [.SSH]
%DELETE-E-DELVER, explicit version number or wild card required

A version number you say? This excellent filesystem has versioning built in.

 $ DEL [.SSH];1
%DELETE-W-SEARCHFAIL, error searching for EISNER$DRA3:[DECUSERVE_USER.EXAMPLE.SSH].;1
-RMS-E-FNF, file not found

The version number inside the brackets?

 $ DEL [.SSH;1]
%DCL-W-DIRECT, invalid directory syntax - check brackets and other delimiters

The DIR command shows me that the folder is named [.SSH.DIR]. Lets try that:

 $ del [.SSH.DIR];1
 %DELETE-W-SEARCHFAIL, error searching for EISNER$DRA3:[DECUSERVE_USER.EXAMPLE.SSH.DIR].;1
 -RMS-E-DNF, directory not found
 -SYSTEM-W-NOSUCHFILE, no such file

At this point in time I thought that maybe I had to remove all the files first inside the folder. One by one I tried:

 $ DIR [.SSH]

Directory EISNER$DRA3:[DECUSERVE_USER.EXAMPLE.SSH]

AUTHORIZATION.;3    REMY-GATEWAY.PUB;1

Total of 2 files.


 $ DEL [.SSH]AUTHORIZATION.;3
 $ DEL [.SSH]REMY-GATEWAY.PUB;1
 $

Folder is empty now:

 $ DIR [.SSH]
%DIRECT-W-NOFILES, no files found

Now I surely must be able to remove the folder, right?

$ DEL [.SSH]
%DELETE-E-DELVER, explicit version number or wild card required

Sadly not. Reading through the docs I figured out the correct command to recursively delete all files in a folder:

   $ DEL [.SSH]*.*;*
   $

The command fails the second time since there are no more files:

 $ DEL [.SSH]*.*;*
%DELETE-W-SEARCHFAIL, error searching for EISNER$DRA3:[DECUSERVE_USER.EXAMPLE.SSH]*.*;*
-RMS-E-FNF, file not found

If you happen to have subfolders, add the /ERASE flag to recursively delete everything:

$ DEL /ERASE [.SSH]*.*;*

Finally the correct DEL syntax, permission error!

Reading the documentation page some more I figured out the correct syntax, no brackets and no leading perion:

 $ DEL SSH.DIR;1
%DELETE-W-FILNOTDEL, error deleting EISNER$DRA3:[DECUSERVE_USER.EXAMPLE]SSH.DIR;1
-RMS-E-PRV, insufficient privilege or file protection violation

Different error message, so we're getting there. The manual states:

This command requires delete (D) access to the file and write (W) access to the parent directory.

Reading, again, the excellent documentation shows me that there is an ACL system and a permission system. For now I tried the permission system first.

I figured out that SHOW SECURITY is the command to see the permissions. Permissions on OpenVMS are very different as well from your standard *NIX permissions.

 $ SHOW SECURITY SSH.DIR;1

EISNER$DRA3:[DECUSERVE_USER.EXAMPLE]SSH.DIR;1 object of class FILE
     Owner: [EXAMPLE]
     Protection: (System: RWE, Owner: RWE, Group, World)
     Access Control List: <empty>

Using the SET FILE command we can explicitly add the D permission for the O (Owner) , which is for deletion:

$ SET FILE/PROTECTION=O:RWED SSH.DIR;1
$

It did update the permissions:

EISNER$DRA3:[DECUSERVE_USER.EXAMPLE]SSH.DIR;1 object of class FILE
     Owner: [EXAMPLE]
     Protection: (System: RWE, Owner: RWED, Group, World)
     Access Control List: <empty>

Would I now finally be able to remove this directory?

   $ DEL SSH.DIR;1
   $

Yay! No error message! And no more folder:

 $ dir [.SSH]
%DIRECT-E-OPENIN, error opening EISNER$DRA3:[DECUSERVE_USER.EXAMPLE.SSH]*.*;* as input
-RMS-E-DNF, directory not found
-SYSTEM-W-NOSUCHFILE, no such file

Conclusion

What have we learned today?

  • Syntax of the DIR command is not the same as for the DEL command, the latter does not require brackets and a leading period.
  • Directories must be empty before they can be removed
  • Removing all files in a folder is possible
  • Removing all directories and files recursively is also possible with the /ERASE flag
  • Deleting a directory requires the explicit D (DELETE) permission to be set on that folder

And still no OpenSSH Public key authentication. Enough OpenVMS for this evening, SSH will be next.


Tags: alpha  blog  dec  decus  itanium  openvms  pdp  simh  vax  vms