zoukankan      html  css  js  c++  java
  • 【Linux常见命令】rm命令

    rm - remove files or directories

    rm命令用于删除一个文件或者目录。

    语法:
      rm [OPTION]... FILE...

    参数:

    • -f 强制删除文件
    • -r 递归,用于删除目录
    • -fr 强制不提示删除目录,不推荐使用,非常危险
    • -i 删除前逐一询问确认

    删除一个文件一般用rm oldboy.txt,此法会提示你确认,推荐初学者使用。
    rm -f oldboy.txt 方法不提示确认直接删除,比较危险,不推荐初学者使用。

    [root@oldboy data]# ls
    info.txt  number.txt  oldboy.txt  old.txt
    [root@oldboy data]# rm old.txt
    rm: remove regular file `old.txt'? y
    [root@oldboy data]# rm -f info.txt
    [root@oldboy data]# ls
    number.txt  oldboy.txt

    另外,对于文件的删除禁止使用"rm -fr 文件名",这种杀鸡用牛到的做法。必须禁止掉,最多是"rm -f 文件"。

    rm -fr 一般用来强制删除目录不提示,非常危险。

    [root@oldboy data]# rm -f /data
    rm: cannot remove `/data': Is a directory
    [root@oldboy data]# rm -fr /data
    [root@oldboy data]# ls
    [root@oldboy data]# cd /
    [root@oldboy /]# ls
    bin   etc   lib64       mnt   root     srv  usr
    boot  home  lost+found  opt   sbin     sys  var
    dev   lib   media       proc  selinux  tmp

    特别提示:
    初学者尽量不要用rm命令,那么如果必须要删除呢?
    可以用mv替代rm,也就是把文件移动到/tmp 下,然后等/tmp分区将要满时一次性删除,减少犯错。

    这种把/tmp目录当做回收站对初学者是个不错的方法。

  • 相关阅读:
    numpy.clip(a, a_min, a_max, out=None)(values < a_min are replaced with a_min, and those > a_max with a_max.)
    pytorch使用过程中遇到的一些问题
    conda管理包
    python argparse模块
    pytorch中设定使用指定的GPU
    Linux下dpkg的用法
    python pdb模块
    ubuntu SSH 连接、远程上传下载文件
    Linux中执行shell脚本命令的4种方法总结
    python linux安装anaconda
  • 原文地址:https://www.cnblogs.com/zoe233/p/11815543.html
Copyright © 2011-2022 走看看