To protect file from deletion in Linux system, the chattr command is able to set the attributes that protects the file.
chattr +a my_protected_file.txt
chattr +a == means that the file can be appended and the file can't be deleted as well.
To set the file to immutable, "+i" attribute can be used.
chattr +i the_protected_file.txt
Immutable file is protected from deletion and the original contents of the file is also preserved because no changes can be made.
This command below:
ls xx*.txt >> the_protected_file.txt
The command above will show "permission denied" if the file is immutable.
If the file is set with +a, then the above command will append the output of "ls" to the file.
To unset or removed the attribute use the minus sign, "-a", "-i".
For example, chattr -a the_protected_file.txt or chattr -i the_protected_file.txt
To know more about chattr type the command below:
man chattr
chattr --help
info chattr
This wiki link shows some nice info as well: https://en.wikipedia.org/wiki/Chattr
To check if the file has attribute settings, follow the example below:
lsattr the_protected_file.txt
The lsattr command will show whether the file or directory has attribute settings.
chattr +a my_protected_file.txt
chattr +a == means that the file can be appended and the file can't be deleted as well.
To set the file to immutable, "+i" attribute can be used.
chattr +i the_protected_file.txt
Immutable file is protected from deletion and the original contents of the file is also preserved because no changes can be made.
This command below:
ls xx*.txt >> the_protected_file.txt
The command above will show "permission denied" if the file is immutable.
If the file is set with +a, then the above command will append the output of "ls" to the file.
To unset or removed the attribute use the minus sign, "-a", "-i".
For example, chattr -a the_protected_file.txt or chattr -i the_protected_file.txt
To know more about chattr type the command below:
man chattr
chattr --help
info chattr
This wiki link shows some nice info as well: https://en.wikipedia.org/wiki/Chattr
To check if the file has attribute settings, follow the example below:
lsattr the_protected_file.txt
The lsattr command will show whether the file or directory has attribute settings.
Cheers. Till next time.
================================
Free Android Apps:
Click on links below to find out more:
Linux Android App cheat sheet:
Multiplication Table for early learners
Catholic Rosary Guide for Android:
Divine Mercy Chaplet Guide (A Powerful prayer):
Comments
Post a Comment