What does linux rm mean?

Apr 14, 2022 pm 04:00 PM
linux rm

In Linux, the full name of rm is "remove", which means "delete". It is used to delete a file or directory. The syntax is "rm [option] file or directory"; this command can permanently delete files. The specified file or directory in the system, and the system will not generate any prompt message when deleting it; if the file is not backed up, it will not be restored.

What does linux rm mean?

#The operating environment of this tutorial: CentOS 6 system, Dell G3 computer.

Linux rm, full English spelling: remove.

What does linux rm mean?

#Linux rm command is used to delete a file or directory.

rm is a powerful deletion command that can permanently delete specified files or directories in the file system. When using the rm command to delete a file or directory, the system will not generate any prompt message. The basic format of this command is:

rm [选项] 文件或目录
Copy after login

Options:

  • -f: force deletion (force), the opposite of the -i option, use - f, the system will no longer ask, but directly delete the target file or directory.

  • -i: Just the opposite of -f. Before deleting a file or directory, the system will give a prompt message. Using -i can effectively prevent accidental deletion. Useful files or directories.

  • -r: Recursive deletion, mainly used to delete directories. It can delete the specified directory and all the content it contains, including all subdirectories and files.

Note that the rm command is a destructive command because the rm command will permanently delete the file or directory. This means that if the file or directory is not deleted, After making a backup, once you delete it using the rm command, it cannot be restored. Therefore, be careful when using the rm command to delete a directory.

How to use the rm command:

1. Omit the options

If no options are added to the rm command, then The default execution is "rm -i file name", which means that before deleting a file, it will ask whether to delete it. For example:

[root@localhost ~]# touch cangls
[root@localhost ~]# rm cangls
rm:是否删除普通空文件"cangls"?y
#删除前会询问是否删除
Copy after login

2. Delete the directory

If you need to delete the directory, you need to use the "-r" option. For example:

[root@localhost ~]# mkdir -p /test/lm/movie/jp
#递归建立测试目录
[root@localhost ~]# rm /test
rm:无法删除"/test/": 是一个目录
#如果不加"-r"选项,则会报错
[root@localhost ~]# rm -r /test
rm:是否进入目录"/test"?y
rm:是否进入目录"/test/lm/movie"?y
rm:是否删除目录"/test/lm/movie/jp"?y
rm:是否删除目录"/test/lm/movie"?y
rm:是否删除目录"/test/lm"?y
rm:是否删除目录"/test"?y
#会分别询问是否进入子目录、是否删除子目录
Copy after login

You will find that if each level of directory and each file needs to be confirmed, it will be a disaster in actual use!

3. Forced deletion.

If there are 10,000 subdirectories or subfiles in the directory to be deleted, then ordinary rm deletion requires at least 10,000 confirmations. Therefore, when actually deleting files, we will choose to force delete. For example:

[root@localhost ~]# mkdir -p /test/lm/movie/jp
#重新建立测试目录
[root@localhost ~]# rm -rf /test
#强制删除,一了百了
Copy after login

After adding the force function, deletion will become very simple, but it should be noted that data cannot be recovered after force deletion, unless relying on third-party data recovery tools, such as extundelete, etc. But please note that data recovery is difficult to restore complete data. Generally, it is very rare to recover 70%~80%. Therefore, instead of betting on data recovery, it is better to develop good operating habits.

Although the "-rf" option is used to delete directories, no error will be reported when deleting files. Therefore, for ease of use, generally the "-rf" option will be used directly whether deleting files or directories.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What does linux rm mean?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1243
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

git software installation git software installation Apr 17, 2025 am 11:57 AM

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

See all articles