Remove files under Linux under Delete file completely

Source: Internet
Author: User

Linux Delete Folder command

Linux Delete directory is very simple, many people are still accustomed to using rmdir, but once the directory is not empty, into deep distress, now use the RM-RF command.
Direct RM is OK, but add two parameters-rf namely: RM-RF directory Name

Delete directory, file rm (remove)

Feature Description: Deletes a file or directory.
Syntax: RM [-dfirv][--help][--version][file or directory ...]
Supplemental Note: Perform RM directives to delete files or directories, and if you want to delete the directory you must add the parameter "-r", otherwise the preset will only delete the file.
Parameters
-D or –directory deletes the hard connection data of the directory to be deleted directly to 0, deleting the directory.
-F or –force forcibly deletes a file or directory.
-I or –interactive ask the user before deleting the existing file or directory.
-R or-R or –recursive recursively, all files and subdirectories under the specified directory are processed together.
The-V or –verbose displays the instruction execution process.

1 Deleting folders

DE>RM-RF filenamede>

-Delete Folder instance:

Rm-rf/var/log/httpd/access

The/var/log/httpd/access directory and all the files and folders under it will be deleted
Need to be reminded: Use this RM-RF must be extra careful, Linux has no Recycle Bin

2 Deleting files

De>rm-f filenamede>
You must be careful when using RM-RF, Linux does not have a recycle Bin


Delete files other than the specified file

First, Linux delete files and folders The following commands are commonly used:

Delete File: RM file

Delete folder: Rm-rf dir
It should be noted that rmdir can only delete empty folders.

Delete all documents other than the development document (folder)?

1, Method 1, the more troublesome approach is:
Copy the file you want to keep to another folder, and then delete the directory, and then return the move that needs to be retained.
MV Keep. /#保留文件 (clip) Keep
RM-RF * #删除当前文件夹里的所有文件
Mv.. /keep./#将原来的东西移动回来

2, Method 2, you need to do in the current folder:
Rm-rf! (keep) #删除keep文件之外的所有文件
Rm-rf! (Keep1 | keep2) #删除keep1和keep2文件之外的所有文件


completely delete files in Linux

Shred the method of deleting a file completely:

$ shred-u File

Shred uses random content to overwrite the nodes and blocks of the file, and deletes the file (-u parameter).

If you want to erase a bit more thoroughly you can add the-z parameter, which means you 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, such as want to completely clear the contents of/DEV/SDB1 partition can be this way:

$ SHRED/DEV/SDB1 (note do not add-u parameter)

Shred's detailed parameters:
-F,--force Change permissions allow write (if necessary)

-N,--iterations=n rewrite n times, defaults to 3 times

--random-source=file reads data from a specified file

-S,--size=n the file to a fixed size (you can use suffixes such as K, M, C, etc.)

-U, truncate and remove files after--remove rewrite

-V,--verbose show progress

-Z,--zero-add overwrite data with 0

–HELP Display Help

–version Display version Information

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.