How to apply a restriction using chattr to all files in a directory? cURL Command in Linux: 30 Powerful Examples Unveiled LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. TechnologyAdvice does not include all companies or all types of products available in the marketplace. Here the list of various options that can be used with chattr command: -R : Used for displaying the list of attributes of directories and their contents recursively. Now try to delete the directory and its files. This post showed you how to use the chattr command in Ubuntu Linux. Yes, it can help you avoid encountering the "Oh! System files such as shadow and passwd are very useful file which contains all users information and password. Attributes are not the same as file permissions. Some attributes, such as a (append-only), may only be modified by the root user: Attributes which apply only to directories, such as D, are not set on regular files, successfully no error will be returned. Over 10,000 Linux users love this monthly newsletter. How to provide append-only permission to a file? The format of a symbolic mode is +-= [aAcCdDeijsStTu]. I hope this article will help you to set and unset attribute on file and folder. If an attribute requires root privileges, but you are not running the command as root, chattr will not change any attributes for that file. Now try to replace already existing content on a file test_file.txt, you will get error Operation not permitted. Example: If we want to create a newfile_name = jayesh1. Once the i attribute has been set the file can only be changed or deleted once the attribute is removed by the root user. Your billing info has been updated. You cannot overwrite the file with redirection (>): Append-only files may not be moved, removed, renamed, or hard-linked. If this attribute is set on a directory, new files created in that directory get this attribute set. To use the chattr command, all you have to do is follow the simple command syntax: Basically, you are given certain options in [operator] and [flags] by which you can tweak the behavior of the chattr command. The chattr command is used to change a file attribute in Ubuntu Linux. The command line options are switches or flags that determine how the commands are executed or controlled. This command will reverse the immutable effect on servo.txt file as applied in first example. Simply run the chattr command to invoke it. Description Syntax: chattr Mode strings Syntax: lsattr List of attributes Fortunately, there is a command called chattr that is designed for just such cases. For example, prevent the file from being renamed, moved, deleted, or even modified. How to Add and Scan a Host in OpenVAS for vulnerabilities? This is also possible using chattr through the a option. For example, if you want to make a file immutable, run the commands below: To view attributes of files, run the commands below: It should display a similar line as shown below: To revert the change and remove the immutable attribute, run the commands below: You can also combine multiple attributes with the chattr command. (a question mark). The consent submitted will only be used for data processing originating from this website. -a : Used for listing all files in directory along with hidden files (the files which starts with '.'). Type the following command to write protect /etc/shadow file on a Linux: # chattr +i /etc/shadow. To check the immutable permission of a specified directory; the rm command is utilized to remove the file.py present in the Org directory. Basically, the chattr command is used to change file attributes on a Linux file system. But what if you actually want to delete the file?