红联Linux门户
Linux帮助

请问一下rm命令和管道结合使用的问题

发布时间:2009-08-30 16:26:13来源:红联作者:huyangyang
为什么下面两个命令的执行结果是一样的?
[root@localhost ~]# rm
rm: missing operand
Try `rm --help' for more information.
[root@localhost ~]# cat file | rm
rm: missing operand
Try `rm --help' for more information.
难到是管理后面的rm没接收到cat file的输出吗?如果是为什么没有接收到呢?
文章评论

共有 9 条评论

  1. chushihua 于 2014-01-12 20:05:16发表:

    路过!!!
    不发表意见……

  2. qxfsy 于 2013-12-31 07:31:12发表:

    逻辑有问题

  3. huyangyang 于 2009-09-01 08:58:09发表:

    rm `cat file`这个也是没问题的。但是我就是想搞清楚为什么cat file | rm不可以。。

  4. wangyu 于 2009-09-01 00:08:36发表:

    呵呵,如果只有一行,应该可以吧,rm是不能有回车的

  5. maozhx 于 2009-08-31 12:38:32发表:

    rm `cat file`
    试试这个,cat file两边是反引号

  6. huyangyang 于 2009-08-31 11:04:33发表:

    [root@localhost tmp]# ll
    total 80
    -rw-r--r-- 1 root root 0 Jul 29 17:30 1.txt
    -rw-r--r-- 1 root root 0 Jul 29 17:30 2.txt
    -rw-r--r-- 1 root root 0 Jul 29 17:30 3.txt
    -rw-r--r-- 1 root root 18 Aug 6 13:34 file
    drwx------ 2 root root 4096 Jul 29 04:25 gconfd-root
    srwxr-xr-x 1 root root 0 Jul 29 03:06 mapping-root
    -rw-r--r-- 1 root root 5 Jul 29 03:06 scim-bridge-0.3.0.lockfile-0@localhost:0.0
    srwxr-xr-x 1 root root 0 Jul 29 03:06 scim-bridge-0.3.0.socket-0@localhost:0.0
    srw------- 1 root root 0 Jul 29 03:06 scim-panel-socket:0-root
    drwxr-xr-x 2 root root 4096 Jul 29 08:59 test
    drwxr-xr-x 2 root root 4096 Aug 6 12:36 test1
    drwxr-xr-x 2 root wolk 4096 Aug 6 12:36 test2
    drwx------ 2 root root 4096 Jul 29 03:06 virtual-root.0REFly
    [root@localhost tmp]# cat file
    1.txt
    2.txt
    3.txt
    [root@localhost tmp]# cat file | rm
    rm: missing operand
    Try `rm --help' for more information.
    [root@localhost tmp]#

  7. wangyu 于 2009-08-31 10:50:57发表:

    这样吧,你把cat file执行后的内容发来看下,估计是你的格式不正确

  8. huyangyang 于 2009-08-31 10:30:46发表:

    使用管道不是可以把cat file的内容传给rm吗?我要删除的就是file这个文件的内容为名称的文件。

  9. wangyu 于 2009-08-30 22:34:37发表:

    cat是列出文件内容吧,而rm是需要给出文件名才能执行,两者不一样