Linux文本操作命令
cat 查看文件内容
cat filename
cat file1
cat file1 file2 > file3 //合并file1 file2 到file3
more 分屏显示文件内容
more filename
cat filename |more //一个效果 空格查看下一页
head -n 5 filename //查看前5行 查看前N行
tall -n 5 filename 查看最后5行 查看最后N行
stat 查看文件详细信息 stat filename
echo
输出文件内容 echo filename
echo sdfsdf>filename 将sdfsd写入filename中 如果没有filename将会自动创建filename
>
管道重定向至文件,覆盖模式。eg: echo "ww">aa
file1 >file2 //file1内容将会覆盖file2
cat file1 file2 > file3 //file1 file2 覆盖file3
>>
管道重定向至文件,追加模式。
file1 >file2 //file1内容将会添加到file2 file2 原有内容还在
cat file1 file2 > file3 //file1 file2 添加file3 原有内容还在
Linux 搜索命令
grep
文 本 内 容 搜 索 。 - i 忽 略 大 小 写 - n 显 示 匹 配 行
在cat 输出file3的文本中搜索as
find
find <path> <options> find /-namex *
find / -size +1000k|m find / -amin -10 # 查找系统中最后10分钟访问的文件
find ./ -empty 搜索空文件夹
find . -maxdepth 5 //搜索文件深度为5层
find . -regex ".*\.\(txt\|c\)
which
查询程序的存储位置,只会命中一次
whereis
whereis ls 查询ls的存储位置 -b 只搜索二进制文
Linux 正则表达式应用
Linux 正则表达式应用:
find -name 仅匹配文件名
find -regex 匹配的是全文件名(含路径)
如匹配当前目录的abc文件,应用为./abc
查找大文件 •find . -type f -size +800