当前位置:网站首页>wc、grep、tar、vi/vim
wc、grep、tar、vi/vim
2022-08-05 05:19:00 【sologuai】
一、wc
命令格式:
wc [选项]... 目标文件.. (不加选项,则默认统计行数、单词个数、字节数三者)
- -l:统计行数
- -w:统计单词个数
- -c:统计字节数
[[email protected] test]# wc -l 1.txt //统计行数,注意空行也会被统计
4 1.txt
[[email protected] test]# wc -w 1.txt //统计单词数
3 1.txt
[[email protected] test]# wc -c 1.txt //统计字节数,注意换行符也会被统计
13 1.txt
[[email protected] test]# wc 1.txt //不指定选项,默认lwc都显示
4 3 13 1.txt二、grep
grep用于查找文件里符合条件的字符串。
命令格式
grep [选项]… 查找条件 目标文件
- ^……”表示以……开头,“……$”表示以……结尾
- “^$”表示空行
用-i "^a",检索出以a开头的行,且不区分大小写
[[email protected] ~]# grep -i "^a" /etc/passwd
adm:x:3:4:adm:/var/adm:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
alice:x:1002:1003::/home/alice:/bin/bash
Amy:x:1005:1006::/home/Amy:/bin/bash用-v "^$" 过滤出非空行
[[email protected] test]# cat 123.txt //查看123.txt文件内容
111
222
aaa
[[email protected] test]# grep -v "^$" 123.txt //过滤出非空行
111
222
aaa
[[email protected] ~]# cat 123.txt |grep -v '^$' >test.txt //将非空行写入到test.txt文件
[[email protected] test]# cat test.txt //查看test.txt
111
222
aaa三、tar
命令格式:
tar [选项] ... 归档文件名(压缩包名字) 源文件或目录 tar [选项] ... 归档文件名 [-C 目标目录]
- -c:创建(Create).tar 格式的包文件
- -x:解开.tar 格式的包文件
- -C:解压时指定释放的目标文件夹 指定目录
- -f:表示使用归档文件(一般都要带上表示使用tar)
- -v:输出详细信息(Verbose)
- -t:列出归档内容
- -j:调用 bzip2 程序进行压缩或解压
- -z:调用 gzip 程序进行压缩或解压
[[email protected] data]# tar -zcvf vm.tar.gz f1 f2 f3 //将三个文件归档后调用gzip程序压缩成vm.tar.gz
f1
f2
f3
[[email protected] data]# tar -jcvf vm.tar.bz f1 f2 f3 //将三个文件归档后调用bzip2程序压缩成vm.tar.bz2
f1
f2
f3
[[email protected] data]# tar -zxvf vm.tar.gz -C /opt //将vm.tar.gz文件解压缩到/opt目录下
f1
f2
f3
[[email protected] data]# tar -tf ff.tar.gzip //列出归档内容
file01
file02
[[email protected] data]# tar -tvf /tmp/ceshi/ff.tar //详细列举归档文件中的所有文件(包括属性信息)
-rwxr--r-- root/root 87 2022-01-21 17:37 file01
-rw-r--r-- user01/hr 0 2022-01-19 17:01 file02
四、vi/vim
vim是从 vi 发展出来的一个文本编辑器。代码补完、编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用。 vim是vi文本编辑器的增强版。
1.vim编辑器的三种工作模式
命令模式:启动vi编辑器后默认进入命令模式,该模式中主要完成如光标移动、字符串查找,以及删除、复制、粘贴文件内容等相关操作;
输入模式:该模式中主要的操作就是录入文件内容,可以对文本文件正文进行修改、或者添加新的内容。处于输入模式时,vi编辑器的最后一行会出现“–INSERT–”的状态提示信息;
末行模式:该模式中可以设置vi编辑环境、保存文件、退出编辑器,以及对文件内容进行查找、替换等操作。处于末行模式时,vi编辑器的最后一行会出现冒号“:”提示符。
2.命令模式中的基本操作
3.末行模式下的基本操作
边栏推荐
- Mongodb query analyzer parsing
- Autoware--北科天绘rfans激光雷达使用相机&激光雷达联合标定文件验证点云图像融合效果
- 小度 小度 在呢!
- spark算子-wholeTextFiles算子
- Small example of regular expression--remove spaces in the middle and on both sides of the string
- The problem of redirecting to the home page when visiting a new page in dsf5.0
- IJCAI 2022|Boundary-Guided Camouflage Object Detection Model BGNet
- 入门文档01 series按顺序执行
- vim的三种模式
- 【Day1】(超详细步骤)构建软RAID磁盘阵列
猜你喜欢

ACL 和NAT
![[Pytorch study notes] 8. How to use WeightedRandomSampler (weight sampler) when the training category is unbalanced data](/img/29/5b44c016bd11f0c0a9110cf513f4e1.png)
[Pytorch study notes] 8. How to use WeightedRandomSampler (weight sampler) when the training category is unbalanced data

spark operator - map vs mapPartitions operator

入门文档04 一个任务依赖另外一个任务时,需要按顺序执行

入门文档01 series按顺序执行

VLAN详解及实验

Getting Started Documentation 10 Resource Mapping

Technology Sharing Miscellaneous Technologies

什么?CDN缓存加速只适用于加速静态内容?

Getting Started Document 01 series in order
随机推荐
Apache配置反向代理
快问快答—腾讯云服务器常见问题解答
Getting Started 03 Distinguish between development and production environments ("hot update" is performed only in the production environment)
ACL 和NAT
ROS video tutorial
NIO works is analysed
LeetCode Interview Questions
spark算子-map vs mapPartitions算子
markdown编辑器模板
CIPU,对云计算产业有什么影响
spark算子-coalesce算子
【Day1】VMware软件安装
运维工程师,快来薅羊毛
spark算子-textFile算子
LinkSLA坚持用户第一,打造可持续的运维服务方案
Configuration of TensorFlow ObjecDetectionAPI under Anaconda3 of win10 system
入门文档12 webserve + 热更新
OpenCV3.0 is compatible with VS2010 and VS2013
Introductory document 05-2 use return instructions the current task has been completed
专有宿主机CDH