BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello,

 

I have may sas datasets into sub folder sas2001 until sas2024 and I looking for a Unix command to protect the folder and the sas datasets from being deleted.

I have executed the Kernel scirpt below

# Change directory to the target directory
cd /finsys/.../LEGO_6141_Restore_sasdatasets_in_sasdata_folder/Notes_LEGO_6141_test.txt

# Set permissions for all files
find . -type f -exec chmod 644 {} \;

# Set permissions for all directories
find . -type d -exec chmod 755 {} \;

But I was able to delete the file directly from winscp

Any suggestion ?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

In UNIX, deleting a file starts with removing a directory entry. So the necessary permission for deleting a file is the write permission on the directory; if you also need to be able to create files there, removing the write permission is not feasible.

One trick you can do from the OS: create a second physical (within the same physical filesystem) link to the file (ln command). If you accidentally remove the first link, the second link will prevent the actual delete (which means removing the inode and freeing the used clusters), and you can recreate the original directory entry.

 

Having a system backup (daily/incremental) is a total must, of course.

View solution in original post

4 REPLIES 4
SASKiwi
PROC Star

Server backups are the usual way to protect against deletion. In my organisation I simply request a restore of the deleted files. That way you are protected regardless of how files are deleted or corrupted.

Tom
Super User Tom
Super User

Whether or not you can delete a file depends on the permission of the directory the file lives in, not the permissions on the file.

 

Since you told Unix that you were allowed to write to the directory that means you can delete the file.  

 

To prevent you from deleting the file remove the write bit from the directory.  Or have the directory owned by someone else, like a system account.

 

Ksharp
Super User

I am not sure. But it is a desired way to try (adding a password to prevent from deleting).

 

data x(alter='xxx');
 set sashelp.class;
run;

proc delete data=x;run;
Kurt_Bremser
Super User

In UNIX, deleting a file starts with removing a directory entry. So the necessary permission for deleting a file is the write permission on the directory; if you also need to be able to create files there, removing the write permission is not feasible.

One trick you can do from the OS: create a second physical (within the same physical filesystem) link to the file (ln command). If you accidentally remove the first link, the second link will prevent the actual delete (which means removing the inode and freeing the used clusters), and you can recreate the original directory entry.

 

Having a system backup (daily/incremental) is a total must, of course.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 362 views
  • 5 likes
  • 5 in conversation