linux 清空文件
将Linux文件清空的几种方法
1、使用重定向的方法
[root@centos7 ~]# du -h test.txt
4.0K test.txt
[root@centos7 ~]# > test.txt
[root@centos7 ~]# du -h test.txt
0 test.txt
2、使用true命令重定向清空文件
[root@centos7 ~]# du -h test.txt
4.0K test.txt
[root@centos7 ~]# true > test.txt
[root@centos7 ~]# du -h test.txt
0 test.txt
3、使用cat/cp/dd命令及/dev/null设备来清空文件
[root@centos7 ~]# du -h test.txt
4.0K test.txt
[root@centos7 ~]# cat /dev/null > test.txt
[root@centos7 ~]# du -h test.txt
0 test.txt
###################################################
[root@centos7 ~]# echo "Hello World" > test.txt
[root@centos7 ~]# du -h test.txt
4.0K test.txt
[root@centos7 ~]# cp /dev/null test.txt
cp:是否覆盖"test.txt"? y
[root@centos7 ~]# du -h test.txt
0 test.txt
##################################################
[root@centos7 ~]# echo "Hello World" > test.txt
[root@centos7 ~]# du -h test.txt
4.0K test.txt
[root@centos7 ~]# dd if=/dev/null of=test.txt
记录了0+0 的读入
记录了0+0 的写出
0字节(0 B)已复制,0.000266781 秒,0.0 kB/秒
[root@centos7 ~]# du -h test.txt
0 test.txt
4、使用echo命令清空文件
[root@centos7 ~]# echo "Hello World" > test.txt
[root@centos7 ~]# du -h test.txt
4.0K test.txt
[root@centos7 ~]# echo -n "" > test.txt ==>要加上"-n"参数,默认情况下会"\n",也就是回车符
[root@centos7 ~]# du -h test.txt
0 test.txt
5、使用truncate命令清空文件
[root@centos7 ~]# du -h test.txt
4.0K test.txt
[root@centos7 ~]# truncate -s 0 test.txt -s参数用来设定文件的大小,清空文件,就设定为0;
[root@centos7 ~]# du -h test.txt
0 test.txt
linux 清空文件的更多相关文章
- linux清空文件内容的几种方式与区别
虽然linux清空文件内容的方式有很多种,但是他们之间有着细微的差别.通过实践我将他们分为两类: 将文件清空,文件大小为0k $ : > filename $ > filename $ ...
- linux清空文件内容的三种方法
linux系统中清空文件内容的三种方法 1.使用vi/vim命令打开文件后,输入"%d"清空,后保存即可.但当文件内容较大时,处理较慢,命令如下:vim file_name:%d: ...
- linux 清空文件内容命令
清空文件内容命令 $ echo "" >log.log > 是重写,覆盖式 >>是尾部追加
- linux:清空文件内容与批量kill 指定程序名的进程
1.常规的清空文件内容方法 1)使用 cat命令显示 /dev/null 的内容然后重定向输出到某个文件,来清空 $ cat /dev/null > filename 2)清空一个文件可以通过 ...
- Linux清空文件内容
日志文件太多,需要清空: echo "" > mylog.log
- linux清空文件夹命令问题
1.linux删除命令是rm.2.命令为rm -rf /文件夹/文件名.3.例如:rm -f /a/b/d.log.删除在a文件夹中的b文件夹中的d.log这个文件.rm -rf /a/b.删除a文件 ...
- linux 清空文件的几种方案
之前要清理文件,都是简单粗暴的rm -rf log文件,最近,发现在某些环境下,是不能删除文件本省的,又必须要清理文件的内容信息,经过亲自实验,目测以下的几种方案是可行的,方案如下: 1.采用vi命令 ...
- linux清空文件方法
1.以下方法,清除后,文件大小为0 2.以下方法,清除后,文件大小为1 多了一个结束字符
- linux清空文件等有用的指令
1). > filename 2). :> filename 3). echo "" > filename (文件大小被截为1字节) 4). ...
随机推荐
- 【转】 多线程之linux线程调度策略
转自:http://blog.csdn.net/byperseverance/article/details/44522731 Linux线程的调度策略分为3个:SCHED_OTHER,SCHED_F ...
- English trip EM2-LP-6B Teacher:Gabriele
Gabriele Gabi n. 加布里尔,加布里埃尔,加布里埃,加布里埃莱(人名) 课上内容(Lesson) 词汇(Key Word ) is married? 结 ...
- 使用Vue cli3搭建一个用Fetch Api的组件
系列参考 ,英文原文参考 我的git代码: https://github.com/chentianwei411/Typeahead 目标: 建立一个输入关键字得到相关列表的组件,用Vuejs2和Fet ...
- Android的组件化和模块化
Android随着业务的增多,而且后续新的需求的增加,代码的修改会变得非常频繁 然后最近在看组件化和模块化 公司的业务没有那么大,所以这种方式我并没有采取 但是还是需要了解下他的使用机制 还有优缺点之 ...
- Bitmap Byte[] 互转
严正声明:作者:psklf出处: http://www.cnblogs.com/psklf/p/5889978.html欢迎转载,但未经作者同意,必须保留此段声明:必须在文章中给出原文连接:否则必究法 ...
- POJ-3107 Godfather 求每个节点连接的联通块数量
dp[n][2],维护儿子的联通块数量和父亲的联通块数量. 第一遍dfs求儿子,第二遍dfs求爸爸. #include<iostream> #include<cstring> ...
- 基于散列的集合 HashSet\HashMap\HashTable
HashSet\HashMap\HashTable 1 基于散列的集合 2 元素会根据hashcode散列,因此,集合中元素的顺序不一定与插入的顺序一致. 3 根据equals方法与hashCode方 ...
- PostgreSQL导出一张表到MySQL
1. 查看PostgreSQL表结构,数据量,是否有特殊字段值 region_il=# select count(*) from result_basic; count --------- ( row ...
- Segments
Segments Given n segments in the two dimensional space, write a program, which determines if there e ...
- Git clone 常见用法
二 克隆Git仓库 1.1 从远程仓库中克隆整个代码仓库 mkdir Demo //在当前路径下新建一个文件夹,用来存放将要拉取的整个代码库 cd Demo //进入这个文 ...