Delete a file permanently in Linux (shred)

Source: Internet
Author: User
To delete files and folders in linux, you can directly use rm to delete them. to delete files or folders completely, you can use the shred command. next I will introduce them to you.

Deleting a directory in linux is very simple. many people are still used to using rmdir. However, once the directory is not empty, it is deeply worried. now we can use the rm-rf command.
You can simply use rm, but you need to add two parameters-rf: rm-rf directory name
Delete directory and file rm (remove)
Function description: delete a file or directory.
Syntax: rm [-dfirv] [-- help] [-- version] [file or directory...]
Note: execute the rm command to delete a file or directory. if you want to delete a directory, you must add the "-r" parameter. Otherwise, only the file will be deleted by default.

Parameters:

-D or-directory: directly delete the hard connection data of the directory to be deleted to 0 and delete the directory.
-F or-force forcibly deletes a file or directory.
-I or-interactive ask the user before deleting an existing file or directory.
-R,-R, or-recursive recursion processes all the files and subdirectories in the specified directory.
-V or-verbose displays the command execution process.

1. delete a folder

De> rm-rf fileNamede>
-Delete a folder instance:
Rm-rf/var/log/httpd/access
The/var/log/httpd/access directory and all files and folders under it will be deleted.
Note that you must be extremely careful when using this rm-rf. linux has no recycle bin.

2. delete an object

De> rm-f fileNamede>
Be careful when using rm-rf. there is no Recycle bin in linux.

Deletes files other than the specified file.

1. common commands for deleting files and folders in Linux are as follows:

Delete file: rm file
Delete a folder: rm-rf dir
Note that rmdir can only delete empty folders.

II. delete all files other than the specified files (folders?

1. Method 1. the troublesome practice is:
Copy the file to be retained to another folder, delete the directory, and move it back.
Mv keep ../# keep the file (folder) keep
Rm-rf * # Delete all files in the current folder
Mv ../keep./# move the original stuff back
2. Method 2, which must be performed in the current folder:
Rm-rf! (Keep) # Delete all files other than the keep File
Rm-rf! (Keep1 | keep2) # Delete all files other than the keep1 and keep2 files

Permanently delete files in Linux

Shred:

$ Shred-u file
Shred will overwrite the node and data block where the file is located with some random content, and delete the file (-u parameter ).
If you want to clear it more thoroughly, you can add the-z parameter, which means to fill it with random data, and then fill it with 0.
$ Shred-u-z file
In addition, shred can also clear the entire partition or disk. for example, to completely clear the content of the/dev/sdb1 partition, you can do this:
$ Shred/dev/sdb1 (do not add the-u parameter)
Detailed shred parameters:
-F, -- force: change the permission to allow write (if necessary)
-N, -- iterations = N rewrite N times. The default value is 3 times.
-- Random-source = FILE: reads data from a specified FILE
-S, -- size = N to smash the file to a fixed size (suffixes such as K, M, and C can be used)
-U, -- remove rewrite and truncate and remove the file
-V, -- verbose shows the progress
-Z, -- zero-add overwrite data with 0
-Help: Display help
-Version: displays version information.

Related Article

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.