将Linux文件清空的几种方法详解程序员
2023-06-13 09:20:05 时间
[[email protected] ~]# du -h test.txt 4.0K test.txt [[email protected] ~]# test.txt [[email protected] ~]# du -h test.txt 0 test.txt2、使用true命令重定向清空文件
[[email protected] ~]# du -h test.txt 4.0K test.txt [[email protected] ~]# true test.txt [[email protected] ~]# du -h test.txt 0 test.txt3、使用cat/cp/dd命令及/dev/null设备来清空文件
[[email protected] ~]# du -h test.txt 4.0K test.txt [[email protected] ~]# cat /dev/null test.txt [[email protected] ~]# du -h test.txt 0 test.txt4、使用echo命令清空文件
################################################### [[email protected] ~]# echo "Hello World" test.txt [[email protected] ~]# du -h test.txt 4.0K test.txt [[email protected] ~]# cp /dev/null test.txt cp:是否覆盖"test.txt"? y [[email protected] ~]# du -h test.txt 0 test.txt
################################################## [[email protected] ~]# echo "Hello World" test.txt [[email protected] ~]# du -h test.txt 4.0K test.txt [[email protected] ~]# dd if=/dev/null of=test.txt 记录了0+0 的读入 记录了0+0 的写出 0字节(0 B)已复制,0.000266781 秒,0.0 kB/秒 [[email protected] ~]# du -h test.txt 0 test.txt
[[email protected] ~]# echo "Hello World" test.txt [[email protected] ~]# du -h test.txt 4.0K test.txt [[email protected] ~]# echo -n "" test.txt == 要加上"-n"参数,默认情况下会"/n",也就是回车符 [[email protected] ~]# du -h test.txt 0 test.txt5、使用truncate命令清空文件
[[email protected] ~]# du -h test.txt 4.0K test.txt [[email protected] ~]# truncate -s 0 test.txt -s参数用来设定文件的大小,清空文件,就设定为0; [[email protected] ~]# du -h test.txt 0 test.txt
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/3030.html
服务器部署程序员系统优化网站设置运维相关文章
- Linux中删除文件的历史记录(linux文件删除记录)
- Linux网络监测:掌握网络状态的实时解决方案(linux网络监测)
- 权限Linux文件权限的管理(linux的文件)
- Linux下固态硬盘的实现方案(linux能用固态硬盘)
- Linux命令:掌握竖线的精妙之处(linux命令竖线)
- Linux嵌入式系统:开发与应用(linux嵌入式的书籍)
- 用户让Linux改变文件所有者(linux修改文件所属)
- Linux实现高效的防盗链技术(linux防盗链)
- 利用Linux系统合并多列文件(linux按列合并文件)
- Linux 分区与挂载:简易教程(linux分区与挂载)
- 映射Linux下实现端口映射的方法(linux创建端口)
- 使用Linux终端Vi编辑器使用技巧(linux终端vi)
- Linux文件查看:掌握这些技巧,让你更高效!(linux下查看文件)
- Linux下磁盘分析:解读磁盘使用情况(linux磁盘分析)
- Linux下强大的图形监控工具(linux图形监控工具)
- Linux蓝屏:系统问题的必答考题(linux蓝屏)
- 击Linux文件权限管理的点点滴滴(linux文件权限点)
- Linux 下快速复制文件的正确方法(linux cp 文件)
- 探索Linux端口运行状态的方法(查看linux端口状态)