Chattr and recursive

rado84

Well-Known Member
Joined
Feb 25, 2019
Messages
757
Reaction score
623
Credits
4,705
I have a stupid question but I'm kinda stuck and I can't figure out what's wrong with the flags.
Normally, in order to make a file immutable (or as I like to call it - immortal), I use "chattr +i [filename]".
But now I wanna do the same to a whole directory so I checked the help of chattr:

Code:
[rado@arch]: ~>$ chattr --help
Usage: chattr [-RVf] [-+=aAcCdDeijPsStTuFx] [-p project] [-v version] files...

The way I understand this help is that the syntax is "chattr -R +i /dirname". But whatever I try (see the code below), it keeps crying that either the action isn't allowed, or that there's no such file or directory:

Code:
[rado@arch]: ~>$ chattr --help
Usage: chattr [-RVf] [-+=aAcCdDeijPsStTuFx] [-p project] [-v version] files...
[rado@arch]: ~>$ cd /usr/share/icons
[rado@arch]: /usr/share/icons>$ ls
Adwaita/  breeze/  default/  hicolor/  HighContrast/
[rado@arch]: /usr/share/icons>$ chattr -R +i breeze/
chattr: Действието не е позволено while setting flags on breeze/
[rado@arch]: /usr/share/icons>$ chattr +i -R breeze/
chattr: Действието не е позволено while setting flags on breeze/
[rado@arch]: /usr/share/icons>$ chattr +i -r breeze/
Usage: chattr [-RVf] [-+=aAcCdDeijPsStTuFx] [-p project] [-v version] files...
[rado@arch]: /usr/share/icons>$ chattr +i -r /breeze
Usage: chattr [-RVf] [-+=aAcCdDeijPsStTuFx] [-p project] [-v version] files...
[rado@arch]: /usr/share/icons>$ chattr +i -R /breeze
chattr: Няма такъв файл или директория while trying to stat /breeze
[rado@arch]: /usr/share/icons>$ chattr -R +i /breeze
chattr: Няма такъв файл или директория while trying to stat /breeze

I wanna make that directory and all files and folders in it to be immutable because I made some changes in it (and I DON'T want it to be updated whenever an update for it is released) but as you can see it won't work. Until today I've never had to use a recursive option with this command, so I'm lost. What am I doing wrong?
 


How about using find?
find /usr/share/icons/breeze/ -exec chattr +i {} \;

You could see which files it'd affect by testing with:
find /usr/share/icons/breeze/ -exec ls -al {} \;

I haven't used chattr enough to know if its recursive works haha :)

Edit: jumping down the chattr rabbit hole, it looks like the R flag is to restore files that have undelete -u set.. which is a really cool feature I didn't know about - only works with ext2, ext3 though .. not the newer filesystems :(
 
Last edited:
Try using sudo. Worked for me.

Code:
sudo chattr -R +i directory/
 
  • Like
Reactions: Rob

Members online


Top