
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
How to Protect Files and Directories from Deleting in Linux
Are you working as a Linux Admin? Do you generally defend script documents or any important files? You might be aware that, Chattr (change Attribute) is a command line Linux utility that is used to set/unset exact attributes to a file in Linux process to comfortable unintended deletion or change of major files and folders, although you’re logged in as a root user.
This article helps you to look after your records or folders that may support in disallowing an unauthorized user to delete your touchy contents.
Protecting File
In the below example abc.txt is the file name
Protecting a file
To protect file, use the following command –
$ sudo chattr +i abc.txt
Now try to remove file, using rm command as shown below –
$ rm abc.txt
The sample output should be like this –
rm: remove write-protected regular file 'abc.txt'?
Removing the protection to file
To remove the protection to file, use the following command –
$ sudo chattr -i abc.txt
To verify the above command, use the following command as shown below-
$ rm abc.txt
The above command removes the file without giving information.
Protecting Directories
In the below example abc is a directory name
Protecting a directory
To protect directory, use the following command –
$ sudo chattr -R +i abc
To verify the above command, use the following command as shown below –
$ rm -r abc
The sample output should be like this –
rm: descend into write-protected directory 'abc'?
Removing protection to the directory
To remove protection to the directory, use the following command-
$ sudo chattr -R -i abc
To verify the above command, use the following command as shown below –
$ rm -r abc
The above command remove the file without giving information.
In the above article, we have learnt about – Learn how to protect files & directories from delete. In our next articles, we will come up with more Linux based tricks and tips. Keep reading!
- Related Articles
- Delete empty files and directories in Linux
- How to move a file, group of files, and directories in Linux?
- How to Find a Specific String or Word in Files and Directories in Linux
- How to remove files and directories in the Linux operating system using the terminal?\n
- How to compare the files available in two directories using diff command in Linux?
- Find the Largest Top 10 Files and Directories On a Linux
- How to Search and Remove Directories Recursively on Linux?
- Listing out directories and files in Python?
- Renaming and Deleting Files in Python
- How to list non-hidden files and directories in windows using Python?
- Generate temporary files and directories using Python
- Listing out directories and files using C#
- How to Copy a File to Multiple Directories in Linux?
- Compare two directories in Linux?
- Skip Hidden Files and Directories During Recursive Copy
