鍍金池/ 教程/ Linux/ wc命令
which命令
ss命令
cp命令使用示例
ps命令
find命令
grep命令
scp命令
rmdir命令
df命令示例
less命令
du命令示例
chown命令示例
route命令
ping命令
more命令
mv命令
ln命令
mkdir命令
rm命令
find命令常用參數(shù)示例
cat命令
find命令-xargs參數(shù)
touch命令
traceroute命令
gzip命令示例
date命令
ls命令
vmstat命令
lsof命令
diff命令
head命令
watch命令
ifconfig命令
cd命令
tail命令
iostat命令
chgrp命令示例
free命令
find命令-exec參數(shù)
tar命令打包解壓示例
cal命令
at命令
netstat命令
wc命令
chmod命令示例
pwd命令
top命令詳解示例
crontab命令(Linux定時(shí)任務(wù))
whereis命令
Linux命令大全教程
nl命令
rcp命令
locate命令

wc命令

Linux系統(tǒng)中的wc(表示:Word Count,不是指廁所)命令的功能為統(tǒng)計(jì)指定文件中的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù),并將統(tǒng)計(jì)結(jié)果顯示輸出。

1.命令格式

wc [選項(xiàng)]文件…

2.命令功能

統(tǒng)計(jì)指定文件中的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù),并將統(tǒng)計(jì)結(jié)果顯示輸出。該命令統(tǒng)計(jì)指定文件中的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù)。如果沒有給出文件名,則從標(biāo)準(zhǔn)輸入讀取。wc同時(shí)也給出所指定文件的總統(tǒng)計(jì)數(shù)。

3.命令參數(shù)

  • -c 統(tǒng)計(jì)字節(jié)數(shù)。
  • -l 統(tǒng)計(jì)行數(shù)。
  • -m 統(tǒng)計(jì)字符數(shù)。這個(gè)標(biāo)志不能與 -c 標(biāo)志一起使用。
  • -w 統(tǒng)計(jì)字?jǐn)?shù)。一個(gè)字被定義為由空白、跳格或換行字符分隔的字符串。
  • -L 打印最長(zhǎng)行的長(zhǎng)度。
  • -help 顯示幫助信息
  • --version 顯示版本信息

4.使用實(shí)例:

實(shí)例1:查看文件的字節(jié)數(shù)、字?jǐn)?shù)、行數(shù)

命令:

wc file2.txt

輸出:

[yiibai@localhost ~]$ cat file2.txt
windows 10
windows 7
linux
C#
java
PHP
python
1003
Hello Word.
[yiibai@localhost ~]$ wc file2.txt
 9 12 63 file2.txt
[yiibai@localhost ~]$

說明:

 9   12     63    file2.txt
行數(shù) 單詞數(shù) 字節(jié)數(shù) 文件名

實(shí)例2:用wc命令怎么做到只打印統(tǒng)計(jì)數(shù)字不打印文件名

命令執(zhí)行和輸出:

[yiibai@localhost ~]$ wc -l file2.txt
9 file2.txt
[yiibai@localhost ~]$ cat file2.txt |wc -l
9
[yiibai@localhost ~]$

說明:使用管道線,這在編寫shell腳本時(shí)特別有用。

實(shí)例3:用來(lái)統(tǒng)計(jì)當(dāng)前目錄下的文件數(shù)

命令:

ls -l | wc -l

輸出:

[yiibai@localhost ~]$ ls -l | wc -l
11
[yiibai@localhost ~]$ ls
file1.txt  file2.txt  logs  newlog.log  patch.txt  project  run.py  scripts  test4  test5
[yiibai@localhost ~]$

說明:數(shù)量中包含當(dāng)前目錄


上一篇:free命令下一篇:df命令示例