Detailed introduction of Linux system command-rm command. Series [59]

The rm command is a commonly used command in the Linux system and can be used to delete files or directories. The following describes how to use the rm command in detail.

1. Command format

rm [options] file/directory

2. Command options

-f: Forcefully delete a file or directory without confirmation.

-i: Ask the user to confirm the deletion before deleting. If the user enters y or Y, delete, otherwise don't.

-r or -R: Recursively delete all files under the directory and its subdirectories. It should be noted that when using the -r or -R option to delete a directory, be extra careful to prevent accidental deletion.

3. Common usage

(1) Delete file

rm filename

Example: delete the file.txt file in the current directory

rm file.txt

(2) Forcibly delete files

rm -f filename

Example: Forcibly delete the file.txt file in the current directory

rm -f file.txt

(3) Delete directory

rm -r directory name

Example: Delete the test directory and its subdirectories and files in the current directory

rm -r test

(4) Forcibly delete the directory

rm -rf dirname

Example: Forcibly delete the test directory and its subdirectories and files in the current directory

rm -rf test

(5) Delete multiple files

rm file1 file2 file3

Example: Delete the three files file1.txt, file2.txt, and file3.txt in the current directory

rm file1.txt file2.txt file3.txt

4. Precautions

(1) Files or directories deleted by the rm command cannot be recovered, so use them with caution.

(2) Do not use the -r or -R option to delete the directory lightly, so as not to cause data loss. It is recommended to use the ls command to view the contents of the directory first.

(3) The rm command does not confirm when deleting a file or directory. Once deleted, it cannot be recovered. Please use it with caution. The -i option is recommended for confirmation.

(4) When deleting a directory, first delete the files and subdirectories under the directory, and then delete the directory itself.

For more details visit: www.tsyvps.com

Guess you like

Origin blog.csdn.net/tiansyun/article/details/130178660