this post was submitted on 28 May 2024
37 points (95.1% liked)

Linux

48287 readers
627 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Hi there, I'm on Bazzite KDE and recently somehow lost a my "gaming" folder..? No idea how but must gave been user faulty, e.g me. Therefore wondering if it's possible to lock certain folders so that this cannot accidentally happen?

all 23 comments
sorted by: hot top controversial new old
[–] axzxc1236@lemm.ee 22 points 5 months ago (1 children)

sudo chattr +i (folder) prevents anything to modify/delete folders and files

Add -R for setting the flag for all subdirectory/files

[–] Sunny@slrpnk.net 5 points 5 months ago (1 children)

Thanks I might try this! However does this allow for reads/writes from the system? Considering this is a folder for games, the files are constantly changing, such as the game save files etc..

[–] DarthYoshiBoy@kbin.social 6 points 5 months ago* (last edited 5 months ago) (2 children)

If you'd like to look into it further. the +i flag in chattr is setting an attribute making the file (everything in Linux is a file, so yes this even means directories) immutable. When a file is immutable, it isn't possible to change the ownership, group, name, or permissions of the file, nor will you be able to write, append, or truncate the file.

It's been a while since I've used it, but I don't believe it's possible to have an immutable directory where you can still modify the contents therein, but I may be misremembering that. It would seem unlikely since adding content to the directory should require that you modify the links for the directory, which shouldn't be allowable with an immutable object?

It's possible that the +a chattr attribute may achieve what you'd prefer. I believe that flag will make it so that files (and again, everything in Linux is a file) can be created and modified, but never deleted. I've actually never used this one, but I can foresee how this still may not be ideal for your wishes since updates to games may expect to be able to delete old content which would be thwarted here. 🤷

[–] lemmyvore@feddit.nl 3 points 5 months ago* (last edited 5 months ago) (1 children)

I don't believe it's possible to have an immutable directory where you can still modify the contents

Not directly under that directory, but you can modify directories under it. Attributes only apply to the directory's own alocation table and child directories have their own tables.

Also you can modify the content of the files in the directory. The attributes only refer to removing or adding files or other operations that modify the directory's table.

[–] DarthYoshiBoy@kbin.social 2 points 5 months ago

Attributes only apply to the directory’s own allocation table and child directories have their own tables.

Thanks. It has been a while, but I was fairly certain that this was the case, glad to have the confirmation. 👍

[–] Sunny@slrpnk.net 1 points 5 months ago

Thanks for the explanation, I luckily solved this with just "basic" changes of permissions in dolphin actually haha, but defo good to know that chattr has these capabilities for future references. Appriciate it 🌻

[–] digdilem@lemmy.ml 11 points 5 months ago (2 children)

Others have answered your question - but it may be worth pointing out the obvious - backups. Annoyances such as you describe are much less of a stress if you know you're protected - not just against accidental erasure, but malicious damage and technical failure.

Some people think it's a lot of bother to do backups, but it is very easily automated with any of the very good free tools around (backup-manager, someone's mentioned timeshift, and about a million others). A little time spent planning decent backups now will pay you back one day in spades, it's a genuine investment of time. And once set up, with some basic monitoring to ensure they're working and the odd manual check once in a blue moon, you'll never be in this position again. Linux comes ahead here in that the performance impact from automated backups can be prioritised not to impact your main usage, if the machine isn't on all the time.

[–] Sunny@slrpnk.net 4 points 5 months ago (1 children)

Definitely a very valid point! I have a server I can back up to aswell, just gotta set it up as you say 👌

[–] zero_gravitas@aussie.zone 4 points 5 months ago

I think it's worth emphasising here: Don't put it off!

There are millions who can tell you from experience that good intentions count for nothing when it comes to backups.

I'd recommend going and setting up Timeshift right now: https://github.com/linuxmint/timeshift

It's easy to set up, it takes literally 10 minutes, and if you decide later you want to use something else, you can just uninstall Timeshift and delete its backups. But in the meantime you'll be protected with backups.

It's literally the first thing I install on a new system and it's saved me multiple times from having to do a complete reinstall.

[–] oo1@kbin.social 3 points 5 months ago

+1 to this.

You can reduce likelihood of any known risk with a preventative measure, in this case the permissions and ownership structure. That is good.

Backup does not reduce likelihood of risk.

It does something more wide-reaching, it mitigates against the bad outcome of loss (from most causes).So it defends from many unknown risks as well as known ones, and unexpected failure of preventative measures. It sort of protects you from your own ignorance and complacency.

Shit - i'm off to do some more work on backup.sh.

[–] MultipleAnimals@sopuli.xyz 10 points 5 months ago

Not really afaik, you can make file immutable with chattr +i /path/to/something but that means you cannot write to it either, which will probably cause problems.

[–] vipaal@aussie.zone 7 points 5 months ago (1 children)

I think looking into man chattr is a good option for this

[–] zero_gravitas@aussie.zone 5 points 5 months ago

People have already given direct answers, and the indirect answer of 'set up regular automated backups' (which everyone should set up right now if they haven't already), but for the sake of throwing another option out there, people could take a look at 'trash-cli': https://github.com/andreafrancia/trash-cli

(P.S. I know OP might not have actually deleted the files with 'rm', but this addresses a broadly similar issue.)

[–] catloaf@lemm.ee 5 points 5 months ago (1 children)

Sure, regular file permissions can do that. You may need to make the folder owner someone else, and set the sticky bit.

[–] Sunny@slrpnk.net 2 points 5 months ago

Yeah actually this was more simple thanI had imagined, I simply changed it so that the owner(me) can only view the folder and not edit. Which totally works in my use case. Thought it would have been more difficult than just changing this tbh, thanks!

[–] Tyoda@lemm.ee 5 points 5 months ago

If you have the space (on a different drive, preferably) you could use Timeshift to create regular snapshots of (parts of) your system. You can restore deleted files like this from even months ago, if you configure it like that.

The first snapshot takes up as much space as all the files you want to save, but every following one only uses as much disk space as the new/changed files since the last snapshot.

[–] Album@lemmy.ca 5 points 5 months ago* (last edited 5 months ago)

Chmod +t

And then chown root

[–] rotopenguin@infosec.pub 2 points 5 months ago

Btrfs, snapper, cp --reflink stuff back out of a snapshot.

[–] Brickardo@feddit.nl 1 points 5 months ago

Can you give ownership of it to someone else?