Linux Commands: RM command

Source: Internet
Author: User

RM command

Function description

LinuxinRMthe command is to delete files and directories. When using-RFparameter, it is important to note that because the directory and the file are deleted,Delete one or more files or directories in a directory, if not used-Roption, youRMThe directory is not deleted. If you useRMto delete a file, you can usually still restore the file to its original state. Use the following:

RM [Options] File ...

Key Features

    • Show entire file at once: Cat filename

    • Create a file from the keyboard: cat > FileName can only create new files, cannot edit existing files

    • Merge several files into one file: Cat file1 file2 > file

Command parameters

Options Meaning
-F The meaning of coercion, ignoring nonexistent files, never giving hints
-I. For interactive deletion
R-r Instructs RM to recursively delete all directories and subdirectories listed in the parameter
-V Detailed display of the steps performed

Delete directory: Rm-rf/path/to/dir

Hazardous operation: RM-RF/* (6 and 7 with hints, 5 not)

Note: All unused files are recommended not to be deleted directly but moved to a dedicated directory: (simulated Recycle Bin), the 4th example below, is also a method of simulating the Recycle Bin.

Example

Use the-i parameter to prompt before deleting

[Email protected] ~]# cd/tmp

[[email protected] tmp]# rm-i BASHRC #加入-i parameter, when deleted will be actively asked to avoid deleting the wrong file

Rm:remove regular file ' BASHRC '? Y

[[email protected] tmp]# rm-i bashrc* #使用通配符, remove all files starting with the TMP BASHRC

Rm:remove regular file ' Bashrc_hlink '? Y

Rm:remove Symbolic link ' bashrc_slink '? Y

Rm:remove regular file ' Bashrc_slink_1 '? Y

Rm:remove Symbolic link ' bashrc_slink_2 '? Y

Use-r recursive removal

[[email protected] tmp]# rmdir/tmp/etc #不能删除, because the directory is not empty,rmdir can only delete empty directory

rmdir:failed to remove '/tmp/etc ': Directory not empty

[[email protected] tmp]# rm-r/tmp/etc #按y确认, press CTRL + C to exit

Rm:descend into directory '/tmp/etc '? ^c

Because the identity is root, the default has been added to the-I option, so you have to press Y to delete!

If you do not want to continue pressing Y, you can press [CTRL]-C] to end the work of RM.

This is a protective action, if you are sure you want to delete this directory without asking, you can do this:         

[Email protected] tmp]#/rm-r/tmp/etc

Precede the command with a backslash to ignore the specified option for alias               

-F parameter, force delete, System not prompt

[Email protected] tmp]# rm-f Test.log

Custom Recycle Bin Features

[email protected] tmp]# Myrm () {d=/tmp/$ (date +%y%m%d%h%m%s) mkdir-p $D; MV "[email protected]" $D && Echo "Moved to $D OK"; }

[[email protected] tmp]# alias rm= ' Myrm '

[[email protected] tmp]# Touch 1.log 2.log 3.log

[email protected] tmp]# LL

Total 0

-rw-r--r--1 root root 0 Apr 7 14:19 1.log

-rw-r--r--1 root root 0 Apr 7 14:19 2.log

-rw-r--r--1 root root 0 Apr 7 14:19 3.log

[Email protected] tmp]# RM [123].log

Moved to/tmp/20160407142017 OK

[Email protected] tmp]# ls/tmp/20160407142017/

1.log 2.log 3.log

Delete files that begin with-

[[email protected] tmp]# touch./-bbb-

[Email protected] tmp]# ls-l

Total 0

-rw-r--r--1 root root 0 Apr 7 14:26-bbb-

[Email protected] tmp]# rm-bbb-

Mv:invalid option--'-'

Try ' MV--help ' for more information.

[Email protected] tmp]# RM./-bbb-

Moved to/tmp/20160407142651 OK

[Email protected] tmp]#


This article is from the "Zhao Dongwei blog" blog, make sure to keep this source http://zhaodongwei.blog.51cto.com/4233742/1871230

Linux Commands: RM command

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.