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 Linux system rm command

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Today I will show you how to use the rm command on the Linux system. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.

Rm command is a command to delete files or directories in the Linux system, its function is very powerful, it can recursively delete a directory and all files and subdirectories under it, let's take a look at the detailed use of the rm command in the Linux system.

1. Linux rm command syntax

The syntax of the rm command is very simple, as follows:

Rm [OPTION]... FILE... Note: the rm command is very dangerous, please make sure what needs to be deleted before executing the rm command!

Parameters.

-f,-- force ignores files that do not exist and never gives prompts. -I,-- interactive asks before deleting-r,-R,-- recursive instructs rm to recursively delete all directories and subdirectories listed in the parameter. -v,-- verbose details the steps in progress-- help displays this help and exits-- version outputs version information and exits the developer

Written by Paul Rubin, David MacKenzie, Richard M. Stallman, and Jim Meyering. 2. An example of using Linux rm command

1) Delete files

[linuxdaxue.com@/home/linuxdaxue.com/rmTest] $ll total 0-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:52 file1 lrwxrwxrwx 1 linuxdaxue.com linuxdaxue.com 5 Jun 16 21:53 file1_link-> file1-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:52 file2-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:53 file3-rw-r--r-- 1 linuxdaxue.com linuxdaxue Com 0 Jun 16 21:53 file4 [linuxdaxue.com@/home/linuxdaxue.com/rmTest] $rm file4 [linuxdaxue.com@/home/linuxdaxue.com/rmTest] $ll total 0-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:52 file1 lrwxrwxrwx 1 linuxdaxue.com linuxdaxue.com 5 Jun 16 21:53 file1_link-> file1-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:52 file2-rw-r--r-- 1 linuxdaxue. Com linuxdaxue.com 0 Jun 16 21:53 file3 in this example We use the rm command to delete a normal file, but the system does not give a prompt to delete it, but deletes the file directly.

2) Interactive deletion of files

[linuxdaxue.com@/home/linuxdaxue.com/rmTest] $ll total 0-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:52 file1 lrwxrwxrwx 1 linuxdaxue.com linuxdaxue.com 5 Jun 16 21:53 file1_link-> file1-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:52 file2-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:53 file3 [linuxdaxue.com@/home/linuxdaxue.com/rmTest] $rm-I file3 rm: remove regular empty file `file3'? Y [linuxdaxue.com@/home/linuxdaxue.com/rmTest] $ll total 0-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:52 file1 lrwxrwxrwx 1 linuxdaxue.com linuxdaxue.com 5 Jun 16 21:53 file1_link-> file1-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:52 file2 in this example, when we use the rm command plus the parameter-I to delete file3, the system asks whether to delete file3.

3) delete the link

[linuxdaxue.com@/home/linuxdaxue.com/rmTest] $ll total 0-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:52 file1 lrwxrwxrwx 1 linuxdaxue.com linuxdaxue.com 5 Jun 16 21:53 file1_link-> file1-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:52 file2 [linuxdaxue.com@/home/linuxdaxue.com/rmTest] $rm file1_link [linuxdaxue.com@/home/linuxdaxue.com/rmTest] $ll total 0-rw -linuxdaxue.com linuxdaxue.com Murray-1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:52 file1-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 21:52 file2 in this example When we delete file1's link file1_link, the system only deletes the file1's link file, file1 is not deleted.

4) Recursive reinforcement to delete folders

[linuxdaxue.com@/home/linuxdaxue.com] $ls dir1 file_new rmTest src testDir [linuxdaxue.com@/home/linuxdaxue.com] $ls testDir [linuxdaxue.com@/home/linuxdaxue.com] $ls rmTest/ file1 file2 [linuxdaxue.com@/home/linuxdaxue.com] $rm-rf rmTest [linuxdaxue.com@/home/linuxdaxue.com] $ls dir1 file_new src testDir what is the Linux system Linux is a free and freely distributed UNIX-like operating system Is a POSIX-based multi-user, multi-tasking, multi-threaded and multi-CPU operating system, using Linux to run major Unix tools, applications and network protocols.

These are all the contents of how to use Linux system rm commands. For more information about how to use Linux system rm commands, you can search for previous articles or browse the following articles to learn! I believe the editor will add more knowledge to you. I hope you can support it!

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

Development

Wechat

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

12
Report