
1.file檢查并顯示檔案類型(determine file type)
一般用法就是file 後面接要檢視的檔案 可以一個或多個
[root@test test]# ll
total 140
-rw-r--r-- 2 root root 18 Oct 17 16:05 ascii.txt
lrwxrwxrwx 1 root root 9 Oct 17 16:06 ascii.txt.link -> ascii.txt
-rw-r--r-- 2 root root 18 Oct 17 16:05 ascii_hardlink.txt
-rwxr-xr-x 1 root root 123364 Oct 17 16:05 cp
-rwxr-xr-x 1 root root 4534 Oct 17 16:04 sshd
[root@test test]# ll
total 140
-rw-r--r-- 2 root root 18 Oct 17 16:05 ascii.txt
lrwxrwxrwx 1 root root 9 Oct 17 16:06 ascii.txt.link -> ascii.txt
-rw-r--r-- 2 root root 18 Oct 17 16:05 ascii_hardlink.txt
-rwxr-xr-x 1 root root 123364 Oct 17 16:05 cp
-rwxr-xr-x 1 root root 4534 Oct 17 16:04 sshd
[root@test test]# file ascii_hardlink.txt
ascii_hardlink.txt: ASCII text
[root@test test]# file ascii.txt ascii.txt.link
ascii.txt: ASCII text
ascii.txt.link: symbolic link to `ascii.txt'
[root@test test]# file ascii.txt ascii.txt.link ascii_hardlink.txt cp sshd
ascii.txt: ASCII text
ascii.txt.link: symbolic link to `ascii.txt'
ascii_hardlink.txt: ASCII text
cp: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
sshd: Bourne-Again shell script text executable
-b:不顯示檔案名,隻顯示檔案類型說明
[root@test test]# ll
total 140
-rw-r--r-- 2 root root 18 Oct 17 16:05 ascii.txt
lrwxrwxrwx 1 root root 9 Oct 17 16:06 ascii.txt.link -> ascii.txt
-rw-r--r-- 2 root root 18 Oct 17 16:05 ascii_hardlink.txt
-rwxr-xr-x 1 root root 123364 Oct 17 16:05 cp
-rwxr-xr-x 1 root root 4534 Oct 17 16:04 sshd
[root@test test]# file ascii.txt cp sshd
ascii.txt: ASCII text
cp: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
sshd: Bourne-Again shell script text executable
[root@test test]# file -b ascii.txt cp sshd
ASCII text
ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
Bourne-Again shell script text executable
[root@test test]#
-L:顯示連結檔案所連結的檔案的類型說明
[root@test test]# ll
total 140
-rw-r--r-- 2 root root 18 Oct 17 16:05 ascii.txt
lrwxrwxrwx 1 root root 9 Oct 17 16:06 ascii.txt.link -> ascii.txt
-rw-r--r-- 2 root root 18 Oct 17 16:05 ascii_hardlink.txt
-rwxr-xr-x 1 root root 123364 Oct 17 16:05 cp
lrwxrwxrwx 1 root root 2 Oct 17 16:27 pc -> cp
-rwxr-xr-x 1 root root 4534 Oct 17 16:04 sshd
[root@test test]# file -L pc
pc: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
[root@test test]# file -L ascii.txt.link
ascii.txt.link: ASCII text
2.cat 連接配接并顯示檔案内容
文法:cat [OPTION]... [FILE]...
通常不接任何選項就是把指定的檔案 的内容傾倒到在标準輸出
[root@test test]# cat /etc/issue.net
CentOS release 6.5 (Final)
Kernel \r on an \m
-n:顯示行号
[root@test test]# cat -n /etc/issue.net
1 CentOS release 6.5 (Final)
2 Kernel \r on an \m
-E:顯示行結束符$
[root@test test]# cat -E /etc/issue.net
CentOS release 6.5 (Final)$
Kernel \r on an \m$
-A:顯示所有字元
[root@test test]# cat -E test.txt
$aaaaaaaaaaaaaaaaaaaa
$
$ggggggggggggggggg
$
$
$
$
$
$dddddddddddddddda
$
$sssssssssssss
$
[root@test test]# cat -A test.txt
aaaaaaaaaaaaaaaaaaaaa^M$
^M$
gggggggggggggggggg^M$
^M$
^M$
^M$
^M$
^M$
ddddddddddddddddda^M$
^M$
ssssssssssssss^M$
^M$
3.tac連接配接并顯示檔案内容(倒序顯示)
[root@test test]# cat test.txt
1
2
3
4
5
[root@test test]# tac test.txt
5
4
3
2
1
4.head:顯示檔案前n行,預設前10行
文法:head (選項) (參數)
-n:指定顯示多少行
[root@test test]# head /etc/init.d/sshd
#!/bin/bash
#
# sshd Start up the OpenSSH server daemon
#
# chkconfig: 2345 55 25
# description: SSH is a protocol for secure remote shell access. \
# This service starts up the OpenSSH server daemon.
#
# processname: sshd
# config: /etc/ssh/ssh_host_key
[root@test test]# head -n 3 /etc/init.d/sshd
#!/bin/bash
#
# sshd Start up the OpenSSH server daemon
提示:在Linux裡head可以直接要顯示的行數目,比如我要看/etc/init.d/sshd 這個檔案的前3行 可以寫成head -3 /etc/init.d/sshd
head -n -數字:顯示除開指定倒數幾行以外的其他所有行的内容(不顯示倒數幾行的内容)
[qiuhom@test ~]$ cat mycron
# this is test work delete *.log file in work dir
#*/10 * * * * /bin/bash /work/test/script.sh >/dev/null 2>&1
#*/05 * * * * /bin/bash /work/test/createfile.sh >/dev/null 2>&1
[qiuhom@test ~]$ head -n -1 mycron
# this is test work delete *.log file in work dir
#*/10 * * * * /bin/bash /work/test/script.sh >/dev/null 2>&1
[qiuhom@test ~]$ head -n -2 mycron
# this is test work delete *.log file in work dir
[qiuhom@test ~]$ head -n -5 mycron
# this is test work delete *.log file in work dir
提示:當然這裡的-n就不能省略。
5.tail:顯示檔案後n行,預設顯示10行
文法:tail (選項) (參數)
-n:指定要顯示多少行
[root@test test]# tail /etc/init.d/sshd
RETVAL=$?
if [ $RETVAL -eq 3 -a -f $lockfile ] ; then
RETVAL=2
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
RETVAL=2
esac
exit $RETVAL
[root@test test]# tail -n 5 /etc/init.d/sshd
*)
echo $"Usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
RETVAL=2
esac
exit $RETVAL
-f:顯示檔案尾部,不退出,等待顯示新追加到檔案裡的内容
提示:這個選項很重要,我們常用在監控某些日志檔案。這個選項可以很清除的看到一個檔案裡增量的資料。和tailf指令一樣的作用。
6.cut:以某種方式從文本中提取一段文字并輸出
文法:cut (選項) (參數)
-d:指定分割符
-f:指定切割後要顯示的字段
-f1:顯示第一個字段
-f1,3:顯示第一個字段和第三個字段
-f1-3:顯示第一個字段到第三個字段
[root@test test]# cat ascii.txt
this is test file
test tail -f command
[root@test test]# cut -d' ' -f2 ascii.txt
is
tail
[root@test test]# cut -d' ' -f1 ascii.txt
this
test
[root@test test]# cut -d' ' -f1,4 ascii.txt
this file
test command
[root@test test]# cut -d' ' -f1-3 ascii.txt
this is test
test tail -f
提示:通常-d 和 -f 都是一起使用。
-b:按照位元組來切割
[root@test test]# cat ascii.txt
this is test file
test tail -f command
提示你好 n
[root@test test]# cut -b5 ascii.txt
[root@test test]# cut -b7 ascii.txt
s
a
[root@test test]# cut -b1,7,9 ascii.txt
tst
tal
\
[root@test test]# cut -b1-7,9 ascii.txt
this ist
test tal
提示\n
-c:按照字元來切割
[root@test test]# cat ascii.txt
this is test file
test tail -f command
提示你好 n
[root@test test]# cut -c3 ascii.txt
i
s
[root@test test]# cut -c3,9 ascii.txt
it
sl
[root@test test]# cut -c3-9 ascii.txt
is is t
st tail
你
[root@test test]# cut -c4-9 ascii.txt
s is t
t tail
示你
7.join:按兩個檔案的相同字段合并
文法:join (選項) (檔案1) (檔案2)
join指令針對每一對具有相同内容的輸入行,整合為一行輸出到标準輸出,預設情況下是把輸入的第一個字段當作連接配接字段,字段之間用空格隔開。
[root@test test]# cat file1
a1 b1 c1
12 13 14
a b c
[root@test test]# cat file2
a1 b1 c2
aa bb cc
11 22 33
[root@test test]# sort file1>file3
[root@test test]# sort file2>file4
[root@test test]# cat file3
12 13 14
a b c
a1 b1 c1
[root@test test]# cat file4
11 22 33
a1 b1 c2
aa bb cc
[root@test test]# join file3 file4
a1 b1 c1 b1 c2
提示:使用join 合并檔案的要求是2個檔案必須是用sort排序後的,否則會提示我們not in sorted order 的字樣
8.sort對檔案内容按指定的規則排序,然後将排序後的結果輸出
文法:sort (選項) (檔案)
預設比較的原則上從首字元向後,依次按ASCII碼值進行比較,輸出預設按照升序進行排序。
[root@test test]# cat file1
a1 b1 c1
12 13 14
a b c
[root@test test]# sort file1
12 13 14
a b c
a1 b1 c1
-n:按照數字大小進行排序(從小到大的順序排序)
[root@test test]# cat xxx
1
5
3
2
4
7
8
6
9
4aa
3dd
6cc
8bb
0hh
7ee
1ff
2gg
[root@test test]# sort -n xxx
0hh
1
1ff
2
2gg
3
3dd
4
4aa
5
6
6cc
7
7ee
8
8bb
9
-r:倒序輸出排序結果
[root@test test]# sort -nr xxx
9
8bb
8
7ee
7
6cc
6
5
4aa
4
3dd
3
2gg
2
1ff
1
0hh
-u:去除重複行
[root@test test]# cat xxx
abc
123
456
789
123
456
abcdef
ab
abc
[root@test test]# sort -u xxx
123
456
789
ab
abc
abcdef
-t -k:指定列進行排序
預設按照第一列排序
[root@test test]# cat xxx
abc--5
123--8
456--0
789--1
123--3
456--4
abcdef--7
ab--6
abc--2
[root@test test]# sort xxx
123--3
123--8
456--0
456--4
789--1
ab--6
abc--2
abc--5
abcdef--7
-t指定分割符-k選項指定分割後按第幾列進行排序
[root@test test]# cat xxx
abc--5
123--8
456--0
789--1
123--3
456--4
abcdef--7
ab--6
abc--2
[root@test test]# sort -t "-" -k2 xxx
456--0
789--1
abc--2
123--3
456--4
abc--5
ab--6
abcdef--7
123--8
提示:-t後面跟的分割符隻能是單個字元的分割符 不能給兩個和兩個以上的,否則會報錯sort: multi-character tab
分組排序案例:以aa-cd-dd-xx中的最後一列xx進行分組,在對每組中的“ip2.2.3.xxx”的最後一列進行排序
[root@test test]# cat ip
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
aa-cc-dd-ef 192.168.11.5
cc-ee-ac-ad 110.121.234.65
cc-ee-ac-ad 110.121.234.165
0f-8e-jj-t2 10.0.0.11
22-5h-9k-8e 172.16.1.25
0f-8e-jj-t2 10.0.0.11
uu-cc-uc-df 127.0.0.11
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.55
aa-cc-dd-ef 192.168.11.25
aa-cc-dd-ef 192.168.11.45
0f-8e-jj-t2 10.0.0.11
uu-cc-uc-df 127.0.0.122
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.55
aa-cc-dd-ef 192.168.11.5
aa-cc-dd-ef 192.168.11.15
22-5h-9k-8e 172.16.1.65
0f-8e-jj-t2 10.0.0.11
uu-cc-uc-df 127.0.0.111
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.55
[root@test test]# sort -t "." -k1.10,1.11 -k4 ip
22-5h-9k-8e 172.16.1.25
22-5h-9k-8e 172.16.1.65
cc-ee-ac-ad 110.121.234.165
cc-ee-ac-ad 110.121.234.65
uu-cc-uc-df 127.0.0.11
uu-cc-uc-df 127.0.0.111
uu-cc-uc-df 127.0.0.122
aa-cc-dd-ef 192.168.11.15
aa-cc-dd-ef 192.168.11.25
aa-cc-dd-ef 192.168.11.45
aa-cc-dd-ef 192.168.11.5
aa-cc-dd-ef 192.168.11.5
ab-cd-ef-gh 12.0.10.2
ab-cd-ef-gh 12.0.10.2
ab-cd-ef-gh 12.0.10.2
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
bc-de-fg-jk 21.11.33.55
bc-de-fg-jk 21.11.33.55
bc-de-fg-jk 21.11.33.55
0f-8e-jj-t2 10.0.0.11
0f-8e-jj-t2 10.0.0.11
0f-8e-jj-t2 10.0.0.11
0f-8e-jj-t2 10.0.0.11
提示:sort排序是按照指定列的第一個數字來排序的,不會按照數字大小排序。所有我們可以看到我們ip最後一位都按照的第一個數字排序的。
9.uniq:去除檔案内容中的重複内容行
文法:uniq (選項) (檔案或标準輸入)
-c:去除蟲重複行,并統計重複行出現的次數
[root@test test]# cat ip
ab-cd-ef-gh 12.0.10.2
ab-cd-ef-gh 12.0.10.2
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
aa-cc-dd-ef 192.168.11.5
cc-ee-ac-ad 110.121.234.65
cc-ee-ac-ad 110.121.234.165
0f-8e-jj-t2 10.0.0.11
ab-cd-ef-gh 12.0.10.2
ab-cd-ef-gh 12.0.10.2
22-5h-9k-8e 172.16.1.25
0f-8e-jj-t2 10.0.0.11
uu-cc-uc-df 127.0.0.11
uu-cc-uc-df 127.0.0.11
uu-cc-uc-df 127.0.0.11
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.55
aa-cc-dd-ef 192.168.11.25
aa-cc-dd-ef 192.168.11.45
aa-cc-dd-ef 192.168.11.45
[root@test test]# uniq -c ip
3 ab-cd-ef-gh 12.0.10.2
1 bc-de-fg-jk 21.11.33.155
1 aa-cc-dd-ef 192.168.11.5
1 cc-ee-ac-ad 110.121.234.65
1 cc-ee-ac-ad 110.121.234.165
1 0f-8e-jj-t2 10.0.0.11
2 ab-cd-ef-gh 12.0.10.2
1 22-5h-9k-8e 172.16.1.25
1 0f-8e-jj-t2 10.0.0.11
3 uu-cc-uc-df 127.0.0.11
1 ab-cd-ef-gh 12.0.10.2
1 bc-de-fg-jk 21.11.33.55
1 aa-cc-dd-ef 192.168.11.25
2 aa-cc-dd-ef 192.168.11.45
[root@test test]#
-d:隻顯示重複的行
[root@test test]# uniq -c ip
3 ab-cd-ef-gh 12.0.10.2
1 bc-de-fg-jk 21.11.33.155
1 aa-cc-dd-ef 192.168.11.5
1 cc-ee-ac-ad 110.121.234.65
1 cc-ee-ac-ad 110.121.234.165
1 0f-8e-jj-t2 10.0.0.11
2 ab-cd-ef-gh 12.0.10.2
1 22-5h-9k-8e 172.16.1.25
1 0f-8e-jj-t2 10.0.0.11
3 uu-cc-uc-df 127.0.0.11
1 ab-cd-ef-gh 12.0.10.2
1 bc-de-fg-jk 21.11.33.55
1 aa-cc-dd-ef 192.168.11.25
2 aa-cc-dd-ef 192.168.11.45
[root@test test]# uniq -d ip
ab-cd-ef-gh 12.0.10.2
ab-cd-ef-gh 12.0.10.2
uu-cc-uc-df 127.0.0.11
aa-cc-dd-ef 192.168.11.45
[root@test test]#
-u:隻顯示唯一的行
[root@test test]# uniq -c ip
3 ab-cd-ef-gh 12.0.10.2
1 bc-de-fg-jk 21.11.33.155
1 aa-cc-dd-ef 192.168.11.5
1 cc-ee-ac-ad 110.121.234.65
1 cc-ee-ac-ad 110.121.234.165
1 0f-8e-jj-t2 10.0.0.11
2 ab-cd-ef-gh 12.0.10.2
1 22-5h-9k-8e 172.16.1.25
1 0f-8e-jj-t2 10.0.0.11
3 uu-cc-uc-df 127.0.0.11
1 ab-cd-ef-gh 12.0.10.2
1 bc-de-fg-jk 21.11.33.55
1 aa-cc-dd-ef 192.168.11.25
2 aa-cc-dd-ef 192.168.11.45
[root@test test]# uniq -u ip
bc-de-fg-jk 21.11.33.155
aa-cc-dd-ef 192.168.11.5
cc-ee-ac-ad 110.121.234.65
cc-ee-ac-ad 110.121.234.165
0f-8e-jj-t2 10.0.0.11
22-5h-9k-8e 172.16.1.25
0f-8e-jj-t2 10.0.0.11
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.55
aa-cc-dd-ef 192.168.11.25
[root@test test]#
和sort結合使用
[root@test test]# cat ip
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
aa-cc-dd-ef 192.168.11.5
[root@test test]# uniq -c ip
1 ab-cd-ef-gh 12.0.10.2
1 bc-de-fg-jk 21.11.33.155
1 ab-cd-ef-gh 12.0.10.2
1 bc-de-fg-jk 21.11.33.155
1 ab-cd-ef-gh 12.0.10.2
1 bc-de-fg-jk 21.11.33.155
1 aa-cc-dd-ef 192.168.11.5
[root@test test]# sort ip |uniq -c
1 aa-cc-dd-ef 192.168.11.5
3 ab-cd-ef-gh 12.0.10.2
3 bc-de-fg-jk 21.11.33.155
[root@test test]#
提示:因為uniq隻能對相鄰的重複行進行去重,是以先sort排序,後去重,這樣比較準确。
10.wc統計檔案的行數、單詞數量或位元組數量
文法:wc (選項) (檔案)
-c:統計位元組數
[root@test test]# cat ip
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
aa-cc-dd-ef 192.168.11.5
[root@test test]# wc -c ip
166 ip
-l:統計檔案的行數
[root@test test]# wc -l ip
7 ip
-m:統計字元數
[root@test test]# wc -m ip
166 ip
-w:統計單詞數
[root@test test]# wc -w ip
14 ip
-L:統計最長行的字元長度
[root@test test]# wc -L ip
24 ip
不加任何選項檢視檔案
[root@test test]# wc ip
7 14 166 ip
提示:不加選項預設分别統計顯示檔案的行數、單詞數、字元數
11.tr替換或删除字元
文法:tr (選項) (字元1) (字元2)
-d:删除指定字元
[root@test test]# cat ip
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
aa-cc-dd-ef 192.168.11.5
[root@test test]# tr -d "ab" <ip
-cd-ef-gh 12.0.10.2
c-de-fg-jk 21.11.33.155
-cd-ef-gh 12.0.10.2
c-de-fg-jk 21.11.33.155
-cd-ef-gh 12.0.10.2
c-de-fg-jk 21.11.33.155
-cc-dd-ef 192.168.11.5
-s:删除重複的其他字元,保留指定連續字元的第一個字元。
[root@test test]# echo "aaaabbbbbccccccddddeeefffggg" |tr -s abcdefg
abcdefg
[root@test test]# echo "aaaabbbbbccccccddddeeefffggg" |tr -s abcd
abcdeeefffggg
-c:處理除開指定字元以外的字元(對指定的字元取反操作)
[root@test test]# cat ip
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
aa-cc-dd-ef 192.168.11.5
[root@test test]# tr -c "ab\n" "**" <ip
ab*******************
b***********************
ab*******************
b***********************
ab*******************
b***********************
aa**********************
[root@test test]#
不加選項把字元1替換成字元2
[root@test test]# cat ip
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
aa-cc-dd-ef 192.168.11.5
[root@test test]# tr "ab" "AB" <ip
AB-cd-ef-gh 12.0.10.2
Bc-de-fg-jk 21.11.33.155
AB-cd-ef-gh 12.0.10.2
Bc-de-fg-jk 21.11.33.155
AB-cd-ef-gh 12.0.10.2
Bc-de-fg-jk 21.11.33.155
AA-cc-dd-ef 192.168.11.5
[root@test test]# tr '[a-z]' '[A-Z]' < ip
AB-CD-EF-GH 12.0.10.2
BC-DE-FG-JK 21.11.33.155
AB-CD-EF-GH 12.0.10.2
BC-DE-FG-JK 21.11.33.155
AB-CD-EF-GH 12.0.10.2
BC-DE-FG-JK 21.11.33.155
AA-CC-DD-EF 192.168.11.5
12.tee多重定向,将資料重定向到檔案的同時提供一份資料副本作為後續指令的标準輸入。簡單說就是把資料從定向到檔案和螢幕上。
文法:tee (選項) (檔案)
-a:向檔案中追加内容,不覆寫。
[root@test test]# ll
total 136
-rwxr-xr-x 1 root root 123364 Oct 17 16:05 cp
-rw-r--r-- 1 root root 166 Oct 17 21:28 ip
lrwxrwxrwx 1 root root 2 Oct 17 16:27 pc -> cp
-rwxr-xr-x 1 root root 1565 Oct 17 16:04 sshd.gz
-rw-r--r-- 1 root root 66 Oct 17 20:16 xxx
[root@test test]# cat ip|tee cat_ip.txt
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
aa-cc-dd-ef 192.168.11.5
[root@test test]# ll
total 140
-rw-r--r-- 1 root root 166 Oct 17 22:09 cat_ip.txt
-rwxr-xr-x 1 root root 123364 Oct 17 16:05 cp
-rw-r--r-- 1 root root 166 Oct 17 21:28 ip
lrwxrwxrwx 1 root root 2 Oct 17 16:27 pc -> cp
-rwxr-xr-x 1 root root 1565 Oct 17 16:04 sshd.gz
-rw-r--r-- 1 root root 66 Oct 17 20:16 xxx
[root@test test]# cat cat_ip.txt
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
aa-cc-dd-ef 192.168.11.5
[root@test test]# ls |tee -a cat_ip.txt
cat_ip.txt
cp
ip
pc
sshd.gz
xxx
[root@test test]# cat cat_ip.txt
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
aa-cc-dd-ef 192.168.11.5
cat_ip.txt
cp
ip
pc
sshd.gz
xxx
[root@test test]#
預設不加選項會覆寫檔案裡的内容
[root@test test]# cat cat_ip.txt
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
ab-cd-ef-gh 12.0.10.2
bc-de-fg-jk 21.11.33.155
aa-cc-dd-ef 192.168.11.5
cat_ip.txt
cp
ip
pc
sshd.gz
xxx
[root@test test]#
[root@test test]# ls |tee cat_ip.txt
cat_ip.txt
cp
ip
pc
sshd.gz
xxx
[root@test test]# cat cat_ip.txt
cat_ip.txt
cp
ip
pc
sshd.gz
xxx
[root@test test]#
作者:Linux-1874
出處:https://www.cnblogs.com/qiuhom-1874/
本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接,否則保留追究法律責任的權利.