Linux命令 wc(word count)-l(lines)用于统计文件中的行数。

文章目录

  • [1、wc -l](#1、wc -l)
  • 2、实战
  • [3、wc --help](#3、wc --help)

1、wc -l

在命令 wc -l 中,-l 的英文全称是 lines。这个选项用于指定 wc(word count,单词计数)命令来统计文件的行数。

例如,当你运行 wc -l load_user_100w_sort.sql 时,wc 会计算 load_user_100w_sort.sql 文件中的行数,并输出结果。

2、实战

bash 复制代码
[root@localhost ~]# ll
总用量 56504
-rw-------. 1 root root     1533 12月  4 2023 anaconda-ks.cfg
-rw-r--r--. 1 root root      191 6月  25 13:29 dump6379.rdb
-rw-r--r--. 1 root root      191 6月  25 13:31 dump6380.rdb
-rw-r--r--. 1 root root      191 6月  25 13:32 dump6381.rdb
-rw-r--r--. 1 root root      583 6月  24 11:13 dump.rdb
-rw-r--r--. 1 root root     1564 12月  4 2023 initial-setup-ks.cfg
-rw-r--r--. 1 root root 57650380 2月  22 2022 load_user_100w_sort.sql
drwxr-xr-x. 3 root root       18 1月   8 18:11 minio
-rw-r--r--. 1 root root      141 6月  25 17:00 nodes-6379.conf
-rw-------. 1 root root   178567 6月   3 13:50 nohup.out
drwxr-xr-x. 2 root root        6 12月  4 2023 公共
drwxr-xr-x. 2 root root        6 12月  4 2023 模板
drwxr-xr-x. 2 root root        6 12月  4 2023 视频
drwxr-xr-x. 2 root root        6 12月  4 2023 图片
drwxr-xr-x. 2 root root        6 12月  4 2023 文档
drwxr-xr-x. 2 root root        6 12月  4 2023 下载
drwxr-xr-x. 2 root root        6 12月  4 2023 音乐
drwxr-xr-x. 2 root root        6 12月  4 2023 桌面
[root@localhost ~]# wc -l load_user_100w_sort.sql 
1000000 load_user_100w_sort.sql
[root@localhost ~]# 

这表示 load_user_100w_sort.sql 文件中有 1,000,000 行(假设文件名中的 "100w" 是 "100万" 的缩写,即一百万)

3、wc --help

bash 复制代码
[root@localhost ~]# wc --help
用法:wc [选项]... [文件]...
 或:wc [选项]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified.  With no FILE, or when FILE is -,
read standard input.  A word is a non-zero-length sequence of characters
delimited by white space.
The options below may be used to select which counts are printed, always in
the following order: newline, word, character, byte, maximum line length.
  -c, --bytes            print the byte counts
  -m, --chars            print the character counts
  -l, --lines            print the newline counts
      --files0-from=文件        从指定文件读取以NUL 终止的名称,如果该文件被
                                        指定为"-"则从标准输入读文件名
  -L, --max-line-length 显示最长行的长度
  -w, --words                   显示单词计数
      --help            显示此帮助信息并退出
      --version         显示版本信息并退出

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
请向<http://translationproject.org/team/zh_CN.html> 报告wc 的翻译错误
要获取完整文档,请运行:info coreutils 'wc invocation'
[root@localhost ~]# 
相关推荐
Tender_光3 分钟前
DNS域名解析服务
运维·服务器
白总Server5 分钟前
Nginx 中间件
大数据·linux·运维·服务器·nginx·bash·web
FreeBuf_36 分钟前
新型恶意软件采用独特混淆技术劫持Docker镜像
运维·docker·容器
望获linux1 小时前
实时操作系统在服务型机器人中的关键作用
linux·机器人·操作系统·开源软件·rtos·具身智能
哈哈幸运2 小时前
Linux Sed 深度解析:从日志清洗到 K8s 等12个高频场景
linux·运维·编辑器·sed
心随_风动2 小时前
主流操作系统对比分析(macOS、Linux、Windows、Unix)
linux·windows·macos
啊吧怪不啊吧2 小时前
Linux常见指令介绍下(入门级)
linux·开发语言·centos
lllsure2 小时前
SpringCloud——负载均衡
服务器·网络·spring cloud
用户867132495743 小时前
5 个开源 MCP 服务器,让您的 AI 代理势不可挡
服务器
陈大大陈3 小时前
基于 C++ 的用户认证系统开发:从注册登录到Redis 缓存优化
java·linux·开发语言·数据结构·c++·算法·缓存