Linux命令学习总结之rm命令_Linux

命令简介:

rm命令用来删除Linux系统中的文件或目录。通常情况下rm不会删除目录,你必须通过指定参数-r或-R来删除目录。另外rm通常可以将该文件或目录恢复(注意,rm删除文件其实只是将指向数据块的索引点(information nodes)释放,只要不被覆盖,数据其实还在硬盘上。如果想要保证文件的内容无法复原,可以使用命令shred 。 另外一般还是要慎用rm -rf *这样的命令。

执行权限 :All User

指令所在路径:/bin/rm

命令语法:

rm [OPTION]... FILE...

命令参数:


参数


长参数


描叙


-f


--force


强制删除,忽略不存在的文件,从不给出提示。


-i


--interactive


交互模式删除文件,删除文件前给出提示。


-r


--recursive


递归的删除目录下面文件以及子目录下文件。


-R


--recursive


递归的删除目录下面文件以及子目录下文件。


-v


--verbose


显示运行时详细信息


--help


显示命令在线帮助


--version


显示命令版本信息

使用示例:

1:查看获取rm命令的帮助信息。

[root@DB-Server kerry]# man rmRM(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 鈥?鈥?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. AUTHOR Written by Paul Rubin, David MacKenzie, Richard Stallman, and Jim Meyering. REPORTING BUGS Report bugs to <bug-coreutils@gnu.org>. COPYRIGHT Copyright 漏 2006 Free Software Foundation, Inc. This is free software. You may redistribute copies of it under the terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. There 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 --helpUsage: 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 recoverthe contents of that file. If you want more assurance that the contents aretruly unrecoverable, consider using shred. Report bugs to bug-coreutils@gnu.org.

2:删除指定文件

如下所示,该目录下有20个文件,删除指定文件后,只剩下19个文件了。

[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:删除文件显示运行时详细信息

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

4:交互模式下删除文件

如下所示,输入y后就会删除文件,不想删除则数据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: 递归删除某个目录下文件以及子目录

如下所示,kerry目录下有test1.txt、 test2.txt 文件,以及子目录tmp, 而子目录下又有文件file1、file2.

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

6: 删除空目录

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

7:删除目录bdump下的所有trc文件类型的文件。

[oracle@DB-Server bdump]$ lsalert_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.trcgsp_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 *.trcremoved `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'

以上所述是本文给大家介绍的Linux命令学习总结之rm命令,希望对大家有所帮助。

时间: 2024-08-03 13:30:25

Linux命令学习总结之rm命令_Linux的相关文章

Linux命令学习总结:rm命令

命令简介:   该 命令用来删除Linux系统中的文件或目录.通常情况下rm不会删除目录,你必须通过指定参数-r或-R来删除目录.另外rm通常可以将该文件或目录恢复 (注意,rm删除文件其实只是将指向数据块的索引点(information nodes)释放,只要不被覆盖,数据其实还在硬盘上.如果想要保证文件的内容无法复原,可以使用命令shred . 另外一般还是要慎用rm -rf *这样的命令. 执行权限 :All User 指令所在路径:/bin/rm   命令语法:   rm [OPTION

Linux命令学习总结:pwd命令

命令简介:     该命令用来显示目前所在的工作目录.指令英文原义:print work directory     执行权限    :All User     指令所在路径:/usr/bin/pwd 或 /bin/pwd 命令语法:     pwd [OPTION]... 命令参数:  参数 长参数 描叙 -L --logical(无效) 当目录为连接路径时,显示连接路径 -P --physical(无效) 显示实际物理路径,而非使用连接(link)路径 --help 显示命令在线帮助(该参数

Linux命令学习总结之rmdir命令_Linux

命令简介: rmdir命令用用来删除空目录,如果目录非空,则会出现错误.可以使用rm删除目录中的文件后,使用rmdir删除目录.也可以使用rm -rf替代rmdir命令.这是一个非常简单的命令. 命令语法: rmdir [OPTION]... DIRECTORY... 命令参数: 参数 长参数 描叙 --ignore-fail-on-non-empty 忽略任何应目录里面有数据文件而造成的错误 -p --parents 递归删除目录 -v --verbose 显示命令执行的详细信息 --help

Linux命令学习总结:cp命令

命令简介:       cp命令用来复制文件或目录.指令英文原义:copy     指令所在路径:/bin/cp   命令语法:               Usage: cp [OPTION]... [-T] SOURCE DEST         or: cp [OPTION]... SOURCE... DIRECTORY         or: cp [OPTION]... -t DIRECTORY SOURCE...   命令参数: 此命令参数是Red Hat Enterprise Li

Linux命令学习总结:reboot命令

命令简介:   该命令用来重启Linux系统.相当于Windows系统中的restart命令.   命令语法: /sbin/reboot [-n] [-w] [-d] [-f] [-i] 或 reboot [-n] [-w] [-d] [-f] [-i]   命令参数: 参数 长参数 描叙 -d 重新启动时不把数据写入记录文件/var/tmp/wtmp -f 强制重新开机,不调用shutdown指令的功能. -h 在系统关机或poweroff之前,将所有的硬盘处于待机模式 -i 关闭网络设置之后

Linux命令学习总结:cd命令

命令简介:     该命令用来切换当前目录.cd 是change directory 的缩写 命令语法:     cd [-L|-P] [dir] 使用示例 1:切换到当前目录的上一级目录 1: [root@DB-Server sysconfig]# pwd 2: /etc/sysconfig 3: [root@DB-Server sysconfig]# cd .. 4: [root@DB-Server etc]# pwd 5: /etc 2:切换到当前目录的上上两层目录 1: [root@DB

Linux命令学习总结:date命令

命令简介:   date 根据给定格式显示日期或设置系统日期时间.print or set the system date and time 指令所在路径:/bin/date 命令语法:   date [OPTION]... [+FORMAT] date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]   命令参数: 参数 描述 -d 显示字符串描述的时间 -f 显示DATEFILE文件中的每行时间 -r 显示文件的最后修改时间 -R 以RFC-28

linux命令学习笔记之dstat命令

dstat可以很方便监控系统运行状况并用于基准测试和排除故障,是一个可以取代vmstat,iostat,netstat和ifstat这些命令的多功能产品. 一.安装方法 # yum install dstat 二.命令参数 -l :显示负载统计量 -m :显示内存使用率(包括used,buffer,cache,free值) -r :显示I/O统计 -s :显示交换分区使用情况 -t :将当前时间显示在第一行 -p, --proc 统计进程信息,(包括runnable.uninterruptibl

Linux命令学习总结:date命令【转】

本文转自:http://www.cnblogs.com/kerrycode/p/3427617.html 命令简介:   date 根据给定格式显示日期或设置系统日期时间.print or set the system date and time 指令所在路径:/bin/date 命令语法:   date [OPTION]... [+FORMAT] date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]   命令参数: 参数 描述 -d 显示字符串