Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the rm and rmdir delete commands in Linux

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to use the rm and rmdir delete commands in Linux. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

Rm command

Usage: rm [option]. A document.

Delete (unlink) files.

-f,-- force forced deletion. Ignore files that do not exist and do not prompt for confirmation

-I need to confirm before deleting

-I requires confirmation before deleting more than three files or deleting recursively. This option is better than-I

Show less content, but can also prevent most errors from happening

-- interactive [= WHEN] confirms the prompt according to the specified WHEN: never,once (- I)

Or always (- I). If this parameter is not added with WHEN, it will always prompt

-- when one-file-system deletes a level recursively, skip all parameters that do not match the command line

The number of files on the file system

-- no-preserve-roo has no special treatment "/"

-- preserve-root does not allow deletion of "/" (default)

-r,-R,-- recursive recursively deletes the directory and its contents

-v,-- verbose shows the steps in detail

-- help displays this help and exits

-- version displays version information and exits

By default, rm does not delete directories. Use the-- recursive (- r or-R) option to delete each given

And all the contents under it.

To delete the file whose first character is "-" (for example, "- foo"), use one of the following methods:

The code is as follows:

Rm-foo

Rm. /-foo

Note that if you use rm to delete a file, you can usually still restore the file to its original state. If you want to make sure

The contents of this file cannot be restored, please consider using shred.

Example:

The code is as follows:

[root@localhost ~] # rm test.php # confirmation is required to delete a file

[root@localhost ~] # rm-f test.php # forced deletion of files is not confirmed

[root@localhost ~] # rm-rfv. / test # forcibly delete the current test directory and show the detailed process of deletion

Rmdir command

Usage: rmdir [option]. Catalogue.

Deletes the specified empty directory.

-- ignore-fail-on-non-empty

Ignore all errors generated only by directory non-null

-p,-- parents deletes the specified directory and its parent folder, such as "rmdir-pa / bmax c'"

It's basically the same as "rmdir a/b/c a'b '".

-v,-- directory details of verbose output processing

-- help displays this help and exits

-- version displays version information and exits

Example:

The code is as follows:

[root@localhost ~] # rmdir test # Delete the test directory. Note that it must be empty.

[root@localhost ~] # rmdir-p a/b/c # Delete the specified directory and its parent folder

After reading the above, do you have any further understanding of how to use the rm and rmdir delete commands in Linux? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report