首页 > 其他 > 详细

bash shell 文本文件操作

时间:2014-03-11 21:21:14      阅读:515      评论:0      收藏:0      [点我收藏+]

一.打开文本文档,查看文本的内容,我们最直观的方式就是用编辑器,并且可以使用vi内部的查找命令查找[参见Vim文字编辑]

bubuko.com,布布扣
vi test.txt#使用vi打开当前目录下的test.txt文本
bubuko.com,布布扣

二.总结bash shell操作的方式

 bash读取文件的内容

  1. cat---concatenate files and print on the standard output(把文件内容串联打印到标准输出)
  2. tac---concatenate and print files in reverse(倒序打印文件内容)
  3. head---output the first part of files(输出文件的第一部分)
  4. tail---output the last part of files(输出文件的剩余部分)
  5. grep---grep searches the named input FILES(or standed input if no files are names)for lines containing a match to the given PATTERN(grep 对已经命名的文件或者还没有命名的输入搜索指定的pattern)
bubuko.com,布布扣
cat test.txt #顺序查看全部内容
tac test.txt#倒序查看所有内容
head -n 10 test.txt#查看前10行的内容
tail -n 10 test.txt #查看后10行的内容
grep .* test.txt#查看所有的内容
bubuko.com,布布扣

bash查看文件的信息

  1. file---determine file type(确定文件的类型)
  2. stat---display file or file system status(展示文件或文件系统的状态)
  3. ls -l ---use a long listing format(用场的文件模式格式化显示文件信息)
bubuko.com,布布扣
file test.txt#查看文件信息
stat test.txt#查看文件状态,也可以查看目录的状态
ls -l test.txt#用详细信息的方式查看当前文件夹
bubuko.com,布布扣

bash创建新的文件

  1. echo---display a line of text(显示文件)
  2. vi---用vi创建文件
  3. touch---Update the access and modification times of each FILE to the current time(更新文件被访问和修改的时间)【能够创建一个空文件,一般为程序所调用】
bubuko.com,布布扣
echo "这是我创建的一个新的文件" >>new.txt#用管道创建一个新的文件

vi new.txt #创建一个新的文件名
...        #用vi编辑文件内容
:wq        #保存文件

touch new.txt#创建一个新的文件
bubuko.com,布布扣

bash shell 文本文件操作,布布扣,bubuko.com

bash shell 文本文件操作

原文:http://www.cnblogs.com/zhanghaiyublog/p/3593480.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!