• bash shell 文本文件操作


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

    vi test.txt#使用vi打开当前目录下的test.txt文本

    二.总结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)
    cat test.txt #顺序查看全部内容
    tac test.txt#倒序查看所有内容
    head -n 10 test.txt#查看前10行的内容
    tail -n 10 test.txt #查看后10行的内容
    grep '.*' test.txt#查看所有的内容

    bash查看文件的信息

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

    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(更新文件被访问和修改的时间)【能够创建一个空文件,一般为程序所调用】
    echo "这是我创建的一个新的文件" >>new.txt#用管道创建一个新的文件
    
    vi new.txt #创建一个新的文件名
    ...        #用vi编辑文件内容
    :wq        #保存文件
    
    touch new.txt#创建一个新的文件
  • 相关阅读:
    hdu5360 Hiking(水题)
    hdu5348 MZL's endless loop(欧拉回路)
    hdu5351 MZL's Border(规律题,java)
    hdu5347 MZL's chemistry(打表)
    hdu5344 MZL's xor(水题)
    hdu5338 ZZX and Permutations(贪心、线段树)
    hdu 5325 Crazy Bobo (树形dp)
    hdu5323 Solve this interesting problem(爆搜)
    hdu5322 Hope(dp)
    Lightoj1009 Back to Underworld(带权并查集)
  • 原文地址:https://www.cnblogs.com/zhanghaiyublog/p/3593480.html
Copyright © 2020-2023  润新知