Linux File Protection and thorough Deletion

Source: Internet
Author: User
Linux File Protection and thorough deletion-general Linux technology-Linux technology and application information. For more information, see. I often see articles about how to use chmod to modify file permissions on the Internet. But there are few articles about the other two classic file operation commands in linux: chattr and lsattr, this is my study note and I hope it will be helpful to new linux users.

The chattr command is useful in many ways to prevent incorrect modification and deletion of important files. Or delete some files that are not using confidential information to make them unrecoverable.

Now let's take a look at the specific usage of the chattr command.

Chattr is used to modify file attributes and requires the permissions of the Super User.

We can use the following command to see the specific usage of the chattr command.
$ Chattr -- help
Usage: chattr [-RV] [-+ = AacDdijsSu] [-v version] files...

Lsattr is used to view file attributes.

You can use the following command to check the specific usage of the lsattr command.
$ Lsattr -- help
Usage: lsattr [-RVadlv] [files...]

Use vi to create a directory named test1.
$ Vi test1

Use lsattr to check the attributes of the test1 file.
$ Lsattr test1
------------- Test1
Property items found to be empty

Let's add an attribute to the test1 file.
$ Chattr + s test1
Use lsattr to check the attributes of the test1 file.
$ Lsattr test1
S ------------ test1
Test1 has an additional s attribute.
S attribute: when the file test1 is deleted, the disk space is cleared. Just like a software that we often use in windows to completely delete files. Deleted files cannot be recovered.

Let's look at another example.
$ Chattr + a test1
A attribute: This attribute means that the file can only append data and cannot be modified or overwritten. In this case, we can only append data to the vi file, but cannot modify the previous data.

It is easy to delete the attributes of an added file. You only need to use-minus to delete the attributes, which is the same as that of chmod.
$ Chattr-a test1
In this way, the limit that test1 can only append data is removed and can be freely modified.

There are many parameters available for chattr. In addition to the two parameters described above
I attribute: This file cannot be modified, deleted, or renamed.
C attribute: when saving the file, compress the file.

There are many other parameters. You can refer to the chattr help. Then let's talk about shred. Using shred/dev/hda can immediately remove your hard disk data and never exceed the limit. Of course, use the correct device file on your hard disk.

By default, various junk data is repeatedly rewritten for 25 times. You can see it by adding the-v parameter.

Snip

$ Shred-v/dev/hda

Shred:/dev/hda: pass 1/25 (random )...

Shred:/dev/hda: pass 2/25 (492492 )...

Shred:/dev/hda: pass 3/25 (000000 )...

Shred:/dev/hda: pass 4/25 (aaaaaa )...

Shred:/dev/hda: pass 5/25 (555555 )...

Shred:/dev/hda: pass 6/25 (cccccc )...

Shred:/dev/hda: pass 7/25 (b6db6d )...

Shred:/dev/hda: pass 8/25 (333333 )...

Shred:/dev/hda: pass 9/25 (6db6db )...

Shred:/dev/hda: pass 10/25 (dddddd )...

Shred:/dev/hda: pass 11/25 (222222 )...

Shred:/dev/hda: pass 12/25 (ffffff )...

Shred:/dev/hda: pass 13/25 (random )...

Shred:/dev/hda: pass 14/25 (eeeeee )...

Shred:/dev/hda: pass 15/25 (924924 )...

Shred:/dev/hda: pass 16/25 (777777 )...

Shred:/dev/hda: pass 17/25 (999999 )...

Shred:/dev/hda: pass 18/25 (111111 )...

Shred:/dev/hda: pass 19/25 (888888 )...

Shred:/dev/hda: pass 20/25 (bbbbbbbb )...

Shred:/dev/hda: pass 21/25 (db6db6 )...

Shred:/dev/hda: pass 22/25 (444444 )...

Shred:/dev/hda: pass 23/25 (666666 )...

Shred:/dev/hda: pass 24/25 (249249 )...

Shred:/dev/hda: pass 25/25 (random )...

Snip

See man shred

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.