Permissions - am I daim bramaged?

Sometimes I want to bang my head when it concerns understanding file permissions.

I want to delete a dir called Test_Dir.

andy is the owner. andy is in group.

When I try to delete it, I get
Operation not permitted.

I have tried

  1. sudo chown -R andy Test_Dir

       sudo rm -R Test_Dir
      [sudo] password for andy: 
      rm: cannot remove 'Test_Dir/Urges1.png': Operation not permitted
      rm: cannot remove 'Test_Dir/Blank.odt': Operation not permitted
      rm: cannot remove 'Test_Dir/old_file.txt': Operation not permitted

Most probably you don’t have the w permission on your directory…
Establish that and everything should be fine…

I did a lsattr and found out that the directory had the append attribute.

I have a thunar custom action that gives that attribute.

I must have accidentally used it on that directory. :slight_smile:

I wish thunar and caja would show attributes like immutable and append.

ls -l in that directory will show you the permissions. If it doesn’t have w permission, just do chmod +w directory_name, then it can be deleted…:slight_smile:

I thought ls does not show things like the append and immutable attributes?

I use lsattr for that.

Should be…

sudo chown -R andy:andy Test_Dir

Which changes both owner and group

Or you can simply use

sudo chown -R andy: Test_Dir

to achieve the same thing.

All that aside, sudo rm -R Test_Dir should remove Test_Dir regardless of who the owner is because with sudo you are root.

Edit:

Sometimes it might be very useful to render a file immutable – nobody (not even the root user) will be able to edit, rename, move or delete this file. The way to do that on a Linux file system is by using file attributes (also called flags) and more specifically the “i“-immutable file attribute.

Your custom action made the files immutable?

Yes, here is the custom action.

Sometimes I want to make sure I don’t accidentally delete a script I have worked hard on.

  echo pass | sudo -S  chattr +i %f

I would like to be able to use an encrypted password, but what I found was very complex.

1 Like

Good idea and interesting solution. Thank you for sharing that. I tend to be a little over zealous about backing up files for the same reasons.

1 Like

I’m not clearly getting it, can you kindly explain how this command works?:confused:

Sure.

It is a custom action that you can make in Thunar.

  echo pass | sudo -S chattr +i %f

The %f is the path to the first selected file.

It echoes a password(not my real one) to chattr so I don’t have to manually input my password for things that require root permission.

    -S, --stdin                   read password from standard input

So you create a custom password that’s stored in the variable pass, it then echoes it to chattr so that it can make the file in %f immutable, am I right?

But what does the -S do? I’ve seen the man, but I don’t see the point- the stderr is the monitor, or is it redirecting to somewhere else?

Sorry, I do not know the answer to that.

There is a nice bash debugger here.

http://bashdb.sourceforge.net/

In that code snippet, pass is not a variable - it is a plain text password and it gets transferred/echoed (trough pipe) to sudo. As sudo by default would transfer that toward command that is supposed to be run with elevated privileges (in this case chattr) one needs to explicitly set with --stdin different behaviour (i.e. sudo should consume stdin not chattr).
(At least that is what my brain think is going on. :wink: )

1 Like

I get it. -S and --stdin are the same.