免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2340 | 回复: 9
打印 上一主题 下一主题

怎么用find清空一个文件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-08-01 13:20 |只看该作者 |倒序浏览
我想用find找到一个文件,然后清空它

> filename

这样可以清空一个文件,但是如何用find加上-exec选项来清空?

谢谢

对不起,刚才忘记说了,我在AIX 5.2下面

论坛徽章:
0
2 [报告]
发表于 2005-08-01 13:32 |只看该作者

怎么用find清空一个文件

find . -name file -exec \> {} \;
试试

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2005-08-01 13:37 |只看该作者

怎么用find清空一个文件

find -name file -exec sed -i '1,$d' {} \;
用>不知道怎么做

论坛徽章:
0
4 [报告]
发表于 2005-08-01 13:48 |只看该作者

怎么用find清空一个文件

原帖由 "doni" 发表:
find . -name file -exec \> {} \;
试试


兄弟,有点问题:
# lsdevora@ /home/lsdevora/bin >find . -name "*.txt" -exec \> {} \;
find: 0652-083 Cannot execute >:: A file or directory in the path name does not exist.
find: 0652-083 Cannot execute >:: A file or directory in the path name does not exist.
find: 0652-083 Cannot execute >:: A file or directory in the path name does not exist.
find: 0652-083 Cannot execute >:: A file or directory in the path name does not exist.
find: 0652-083 Cannot execute >:: A file or directory in the path name does not exist.
find: 0652-083 Cannot execute >:: A file or directory in the path name does not exist.

论坛徽章:
0
5 [报告]
发表于 2005-08-01 13:50 |只看该作者

怎么用find清空一个文件

原帖由 "mocou" 发表:
find -name file -exec sed -i '1,$d' {} \;
用>不知道怎么做


兄弟,sed也有问题


  1. find: 0652-083 Cannot execute >:: A file or directory in the path name does not exist.
  2. # lsdevora@ /home/lsdevora/bin >find . -name "*.txt" -exec sed -i '1,$d' {} \;
  3. sed: Not a recognized flag: i
  4. Usage:  sed [-n] Script [File ...]
  5.         sed [-n] [-e Script] ... [-f Script_file] ... [File ...]
  6. sed: Not a recognized flag: i
  7. Usage:  sed [-n] Script [File ...]
  8.         sed [-n] [-e Script] ... [-f Script_file] ... [File ...]
  9. sed: Not a recognized flag: i
  10. Usage:  sed [-n] Script [File ...]
  11.         sed [-n] [-e Script] ... [-f Script_file] ... [File ...]
  12. sed: Not a recognized flag: i
  13. Usage:  sed [-n] Script [File ...]
  14.         sed [-n] [-e Script] ... [-f Script_file] ... [File ...]
  15. sed: Not a recognized flag: i
  16. Usage:  sed [-n] Script [File ...]
  17.         sed [-n] [-e Script] ... [-f Script_file] ... [File ...]
  18. sed: Not a recognized flag: i
  19. Usage:  sed [-n] Script [File ...]
  20.         sed [-n] [-e Script] ... [-f Script_file] ... [File ...]
复制代码

论坛徽章:
0
6 [报告]
发表于 2005-08-01 13:53 |只看该作者

怎么用find清空一个文件

find . -name "*.f" -exec cp /dev/null {} \;

论坛徽章:
0
7 [报告]
发表于 2005-08-01 13:59 |只看该作者

怎么用find清空一个文件

[quote]原帖由 "biary"]find . -name "*.f" -exec cp /dev/null {} \;[/quote 发表:


兄弟,谢谢你。你的方法可以用

谢谢大家的帮忙,兄弟我懂了。

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
8 [报告]
发表于 2005-08-01 14:01 |只看该作者

怎么用find清空一个文件

[quote]原帖由 "biary"]find . -name "*.f" -exec cp /dev/null {} \;[/quote 发表:


这个通用。偶那个是你的系统不支持sed的-i

论坛徽章:
0
9 [报告]
发表于 2005-08-01 14:58 |只看该作者

怎么用find清空一个文件

原帖由 "mocou" 发表:


这个通用。偶那个是你的系统不支持sed的-i


赫赫,aix里面没有哪个-i,linux下面有。
该死的日本公司松下,他喜欢用ibm的

论坛徽章:
0
10 [报告]
发表于 2005-08-01 18:18 |只看该作者

怎么用find清空一个文件

[quote]原帖由 "biary"]find . -name "*.f" -exec cp /dev/null {} \;[/quote 发表:


find . -name "*.f" -exec cat /dev/null  > {} \;
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP