Linux Command learning Summary: rm command, linux Command summary rm

Source: Internet
Author: User

Linux Command learning Summary: rm command, linux Command summary rm

Command introduction:

This command is used to delete files or directories in Linux. Normally, rm will not delete the directory. You must specify the-r or-R parameter to delete the directory. In addition, rm can usually restore the file or directory. (Note: When rm deletes a file, it only releases the index point pointing to the data block (information nodes), as long as it is not overwritten, the data is still on the hard disk. To ensure that the file content cannot be restored, run the shred command. In addition, you should use commands like rm-rf * with caution.

Execution permission: All User

Command path:/bin/rm

Command syntax:

Rm [OPTION]... FILE...

Command parameters:

Parameters

Long Parameter

Description

-F

-- Force

Force Delete, ignore non-existing files, and never give a prompt.

-I

-- Interactive

Delete a file in interactive mode. A prompt is displayed before deleting the file.

-R

-- Recursive

Recursively delete files in directories and subdirectories.

-R

-- Recursive

Recursively delete files in directories and subdirectories.

-V

-- Verbose

Displays running details

-- Help

Show command online help

-- Version

Display command version information

Example:

 

1: view the help information of the rm command.

[root@DB-Server kerry]# man rm
RM(1)                            User Commands                           RM(1)
 
NAME
       rm - remove files or directories
 
SYNOPSIS
       rm [OPTION]... FILE...
 
DESCRIPTION
       This manual page documents the GNU version of rm.  rm removes each specified file.  By default, it does not remove directories.
 
       If  a  file is unwritable, the standard input is a tty, and the -f or --force option is not given, rm prompts the user for whether to remove the file.  If
       the response is not affirmative, the file is skipped.
 
OPTIONS
       Remove (unlink) the FILE(s).
 
       -f, --force
              ignore nonexistent files, never prompt
 
       -i, --interactive
              prompt before any removal
 
-- No-preserve-root do not treat tables? Why? Specially (the default)
 
       --preserve-root
Fail to operate recursively on success? Why?
 
       -r, -R, --recursive
              remove directories and their contents recursively
 
       -v, --verbose
              explain what is being done
 
       --help display this help and exit
 
       --version
              output version information and exit
 
       By default, rm does not remove directories.  Use the --recursive (-r or -R) option to remove each listed directory, too, along with all of its contents.
 
To remove a file whose name starts with a repository? Why? For example? Foo success? Use one of these commands:
 
              rm -- -foo
 
              rm ./-foo
 
       Note that if you use rm to remove a file, it is usually possible to recover the contents of that file.  If you want more assurance that the  contents  are
       truly unrecoverable, consider using shred.
 
AUTHOR
       Written by Paul Rubin, David MacKenzie, Richard Stallman, and Jim Meyering.
 
REPORTING BUGS
       Report bugs to <bug-coreutils@gnu.org>.
 
COPYRIGHT
Copyright missing 2006 Free Software Foundation, Inc.
       This is free software.  You may redistribute copies of it under the terms of the GNU General Public License 

       is NO WARRANTY, to the extent permitted by law.
 
SEE ALSO
       chattr(1), shred(1)
 
       The full documentation for rm is maintained as a Texinfo manual.  If the info and rm programs are properly installed at your site, the command
 
              info rm
 
       should give you access to the complete manual.
 
rm 5.97                            June 2011                             RM(1)

 

[root@DB-Server kerry]# rm --help
Usage: rm [OPTION]... FILE...
Remove (unlink) the FILE(s).
 
  -f, --force           ignore nonexistent files, never prompt
  -i, --interactive     prompt before any removal
      --no-preserve-root do not treat `/' specially (the default)
      --preserve-root   fail to operate recursively on `/'
  -r, -R, --recursive   remove directories and their contents recursively
  -v, --verbose         explain what is being done
      --help     display this help and exit
      --version  output version information and exit
 
By default, rm does not remove directories.  Use the --recursive (-r or -R)
option to remove each listed directory, too, along with all of its contents.
 
To remove a file whose name starts with a `-', for example `-foo',
use one of these commands:
  rm -- -foo
 
  rm ./-foo
 
Note that if you use rm to remove a file, it is usually possible to recover
the contents of that file.  If you want more assurance that the contents are
truly unrecoverable, consider using shred.
 
Report bugs to bug-coreutils@gnu.org.

2: delete a specified file

As shown in the following figure, there are 20 files in the directory. After the specified file is deleted, only 19 files are left.

[oracle@DB-Server bdump]$ ls -lrt | wc -l
 
20
 
[oracle@DB-Server bdump]$ rm gsp_lgwr_7826.trc
 
[oracle@DB-Server bdump]$ ls -lrt | wc -l
 
19
 

 

3: detailed information about running is displayed when the file is deleted.

[oracle@DB-Server bdump]$ rm -v gsp_lgwr_4617.trc 
 
removed `gsp_lgwr_4617.trc'
 

4: delete files in interactive mode

As shown below, input y will delete the file. If you do not want to delete the file, data n

[oracle@DB-Server bdump]$ rm -iv gsp_lgwr_5005.trc 
 
rm: remove regular file `gsp_lgwr_5005.trc'? y
 
removed `gsp_lgwr_5005.trc'
 
[oracle@DB-Server bdump]$ rm -iv gsp_lgwr_7826.trc 
 
rm: remove regular file `gsp_lgwr_7826.trc'? n
 

5: recursively delete files and subdirectories in a directory

As shown in the following figure, the kerrydirectory contains the test1.txt and test2.txt files, as well as the tmp sub-directories, while the sub-directories have the files file1 and file2.

[root@DB-Server ~]# tree kerry
kerry
|-- test1.txt
|-- test2.txt
`-- tmp
    |-- file1
    `-- file2
 
1 directory, 4 files
[root@DB-Server ~]# rm -rf kerry/

6. delete an empty directory.

[root@DB-Server ~]# mkdir kerry
 
[root@DB-Server ~]# rm -r kerry/
 
rm: remove directory `kerry/'? y
 

 

7. Delete All trc files under the bdump directory.

[oracle@DB-Server bdump]$ ls
alert_GSP.log       gsp_lgwr_20025.trc  gsp_lgwr_5023.trc  gsp_p000_4637.trc  gsp_p000_4718.trc  gsp_p000_5025.trc  gsp_p001_4639.trc  gsp_p001_4720.trc  gsp_p001_5027.trc
gsp_lgwr_19915.trc  gsp_lgwr_4719.trc   gsp_lgwr_5089.trc  gsp_p000_4682.trc  gsp_p000_4739.trc  gsp_p000_5043.trc  gsp_p001_4684.trc  gsp_p001_4741.trc  gsp_p001_5045.trc
[oracle@DB-Server bdump]$ rm -v *.trc
removed `gsp_lgwr_19915.trc'
removed `gsp_lgwr_20025.trc'
removed `gsp_lgwr_4719.trc'
removed `gsp_lgwr_5023.trc'
removed `gsp_lgwr_5089.trc'
removed `gsp_p000_4637.trc'
removed `gsp_p000_4682.trc'
removed `gsp_p000_4718.trc'
removed `gsp_p000_4739.trc'
removed `gsp_p000_5025.trc'
removed `gsp_p000_5043.trc'
removed `gsp_p001_4639.trc'
removed `gsp_p001_4684.trc'
removed `gsp_p001_4720.trc'
removed `gsp_p001_4741.trc'
removed `gsp_p001_5027.trc'
removed `gsp_p001_5045.trc'
 

References:

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


How to Use the linux rm command?

Rm-rf filenem

Apeng @ ubuntu :~ $ Rm -- help
Usage: rm [Option]... file...
Delete An unlink file.

-F, -- force Delete. Ignore nonexistent files and do not Prompt confirmation
-I must be confirmed before deletion
-I requires confirmation before deleting more than three files or recursively deleting them. This option is more advanced than-I
Less content, but can also prevent most errors
-- Interactive [= WHEN]: never, once (-I ),
Or always (-I ). If this parameter is not added with WHEN, the system always prompts
-- When one-file-system recursively deletes a level, all non-conforming command line parameters are skipped.
Number of files on the file system
-- No-preserve-roo is not special "/"
-- Preserve-root cannot delete "/" (default)
-R,-R, -- recursive recursively deletes directories and their contents
-V, -- verbose detailed display steps
-- Help: displays the help information and exits.
-- Version: displays the version information and exits.

By default, rm does not delete the directory. Use the -- recursive (-r or-R) option to delete each given
And all its contents.

To delete a file with the first character "-" (for example, "-foo"), use one of the following methods:
Rm ---foo
Rm./-foo

Note that if you use rm to remove a file, it might be possible to recover
Some of its contents, given sufficient expertise and/or time. For greater
Assurance that the contents are truly unrecoverable, consider using shred.

Please report rm errors to bug-coreutils@gnu.org
GNU coreutils project homepage: <www.gnu.org/software/coreutils/>
GNU software general help: <www.gnu.org/gethelp/>
Please report rm translation errors to <translationproject.org/team/zh_CN.html>
To obtain the complete documentation, run: info coreutils 'rm invocation '... the remaining full text>

Rm commands in Linux

If you delete an object, you can directly use rm;
If you delete a directory, you can use rmdir or rm-rf.

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.