Linux RM Command

Source: Internet
Author: User

The RM command in Linux is to delete files and directories. When using the-r parameter, it is important to note that the directory and files will be deleted.

1 . Command format:

RM [ Options ] file ...

2 . Command function:

Delete one or more files or directories in a directory, and RM does not delete the directory if the-r option is not used . If you use rm to delete a file, you can usually still restore the file to its original state.

3 . Command parameters:

-F,--force mandatory meaning, ignoring nonexistent files, never give hints.

-I,--interactive for interactive deletion

-R,-R,--recursive instructs rm to delete all directories and subdirectories listed in the parameters recursively.

-V,--verbose detailed display of the steps performed

--help Display this help message and exit

--version output version information and exit

command example:

1. -i parameter, ask before deleting

[Email protected] ~]# cd/tmp[[email protected] tmp]# rm-i bashrcrm:remove regular file ' BASHRC '? Y add-i parameter, delete will be actively asked to avoid the deletion of the wrong file [[email protected] tmp]# rm-i bashrc* use wildcards, the TMP under the BASHRC start to delete all Rm:remove Regu Lar file ' Bashrc_hlink '? Yrm:remove Symbolic link ' bashrc_slink '? Yrm:remove regular file ' Bashrc_slink_1 '? Yrm:remove Symbolic link ' bashrc_slink_2 '? Y

2. -R parameter, recursively delete directory

[[email protected] tmp]# rmdir/tmp/etcrmdir:failed to remove '/tmp/etc ': Directory not empty cannot be deleted because the catalog is not empty [[email PR Otected] tmp]# rm-r/tmp/etcrm:descend into directory '/tmp/etc '? ^c Press Y to confirm, press CTRL + C to exit

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

3. -F parameter, force delete, System not prompt

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

4. Custom Recycle Bin function

[[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]# lltotal 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].logmoved to /tmp/20160407142017 ok[[email protected] tmp]#  ls /tmp/20160407142017/1.log  2.log  3.log[[email protected] tmp]# 

5. Delete The file that begins with-

[[email protected] tmp]# touch./-bbb-[[email protected] tmp]# ls-ltotal 0-rw-r--r--1 root root 0 Apr 7 14:26-bbb-[[em AIL 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]#



Reference:

Http://www.cnblogs.com/peida/archive/2012/10/26/2740521.html


This article is from the blog "Write to Yourself", so be sure to keep this source http://zhaodongwei.blog.51cto.com/4233742/1761293

Linux 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.