鍍金池/ 教程/ Linux/ cat命令
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定時任務(wù))
whereis命令
Linux命令大全教程
nl命令
rcp命令
locate命令

cat命令

cat命令的用途是連接文件或標準輸入并打印。這個命令常用來顯示文件內(nèi)容,或者將幾個文件連接起來顯示,或者從標準輸入讀取內(nèi)容并顯示,它常與重定向符號配合使用。

1.命令格式

cat [選項] [文件]…

2.命令功能

cat主要有三大功能:

  1. 一次顯示整個文件:cat filename
  2. 從鍵盤創(chuàng)建一個文件:cat > filename 只能創(chuàng)建新文件,不能編輯已有文件.
  3. 將幾個文件合并為一個文件:cat file1 file2 > file
    命令參數(shù):
    • -A, --show-all 等價于 -vET
    • -b, --number-nonblank 對非空輸出行編號
    • -e 等價于 -vE
    • -E, --show-ends 在每行結(jié)束處顯示$
    • -n, --number 對輸出的所有行編號,由1開始對所有輸出的行數(shù)編號
    • -s, --squeeze-blank 有連續(xù)兩行以上的空白行,就代換為一行的空白行
    • -t-vT 等價
    • -T, --show-tabs 將跳格字符顯示為 ^I
    • -u (被忽略)
    • -v, --show-nonprinting 使用 ^M- 引用,除了 LFDTAB 之外

4.使用實例

實例一

mylog1.log 的文件內(nèi)容加上行號后輸入 mylog2.log 這個文件里。
命令:

cat -n mylog1.log mylog2.log

輸出:

[yiibai@localhost test]$ cat mylog1.log
this is line 1
this is line 2
[yiibai@localhost test]$ cat mylog2.log
log2 this is line 1
log2 this is line 2
log2 this is line 3
[yiibai@localhost test]$ cat -n mylog1.log mylog2.log
     1  this is line 1
     2  this is line 2
     3  log2 this is line 1
     4  log2 this is line 2
     5  log2 this is line 3
[yiibai@localhost test]$

實例二

mylog1.logmylog2.log 的文件內(nèi)容加上行號(空白行不加)之后將內(nèi)容附加到 log.log 里。
命令:

cat -b mylog1.log mylog2.log log.log

輸出:

yiibai@localhost test]$ cat -b mylog1.log mylog2.log >> log.log
[yiibai@localhost test]$ cat log.log
     1  this is line 1
     2  this is line 2
     3  log2 this is line 1
     4  log2 this is line 2
     5  log2 this is line 3
[yiibai@localhost test]$

實例三

使用here doc來生成文件

[yiibai@localhost test]$ cat >log.txt <<EOF
> Hello
> World
> Linux command
> PWD=$(pwd)
> EOF
[yiibai@localhost test]$ ls -l log.txt
-rw-rw-r--. 1 yiibai yiibai 49 Feb 13 03:20 log.txt
[yiibai@localhost test]$ cat log.txt
Hello
World
Linux command
PWD=/home/yiibai/test
[yiibai@localhost test]$

上一篇:rmdir命令下一篇:ps命令