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]# 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命令实战(三)的更多相关文章

  1. Java开发人员必须掌握的Linux命令(三)

    做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开! 学习应该是快乐的,在这个乐园中我努力让自己能用简洁易懂(搞笑有趣)的表达来讲解知识或者技术,让学习之旅充满乐趣,这就是写博 ...

  2. Linux命令实战(一)

    1.pwd(printing working directory)打印当前工作目录路径 [root@test sysconfig]# pwd /etc/sysconfig 2.ls(list)列出当前 ...

  3. Linux命令实战(四)

    1.Linux上的文件管理类命令都有哪些,其常用的使用方法及相关示例演示. 文件或目录的新建 touch :将每个文件的访问时间和修改时间修改为当前时间.若文件不存在将会创建为空文件,除非使用-c或- ...

  4. Linux命令(三)vim编辑器的常用命令

    .subTitle { background: rgba(51, 153, 0, 0.53); border-bottom: 1px solid rgba(0, 102, 0, 1); border- ...

  5. linux命令基础三

    使用cat命令进行文件的纵向合并使用cat命令实现文件的纵向合并: 例如:使用cat命令将baby.age.baby.kg和baby.sex这三个文件纵向合并为baby文件的方法:cat baby.a ...

  6. Linux命令实战(五)

    1.显示/etc目录下,以非字母开头,后面跟了一个字母以及其他任意长度字符的文件或目录. [qiuhom@test ~]$ls -d /etc/[^[:alpha:]][[:alpha:]]* ls: ...

  7. Linux命令-文件管理(三)

    Linux more命令 Linux more 命令类似 cat ,不过会以一页一页的形式显示,更方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会往回(bac ...

  8. Linux命令第三篇

    作业三: 以操作文件的方式,新建一个用户alex echo "alex:x:1200:1200::/home/alex/:/bin/bash" >> /etc/pass ...

  9. 50个常用的Linux命令(三)基础实例

    ls ls -als -l == llls -Aldrwxrwxrwx.  2 root   root       6 Dec 21 20:38 Videos-rwxrwxrwx   1 root   ...

随机推荐

  1. Spring Boot2 系列教程(十三)Spring Boot 中的全局异常处理

    在 Spring Boot 项目中 ,异常统一处理,可以使用 Spring 中 @ControllerAdvice 来统一处理,也可以自己来定义异常处理方案.Spring Boot 中,对异常的处理有 ...

  2. Kubernetes网络插件Flannel的三种工作模式

    跨主机通信的一个解决方案是Flannel,由CoreOS推出,支持3种实现:UDP.VXLAN.host-gw 一.UDP模式(性能差) 核心就是通过TUN设备flannel0实现(TUN设备是工作在 ...

  3. (19)ASP.NET Core EF创建模型(包含属性和排除属性、主键、生成的值)

    1.什么是Fluent API? EF中内嵌的约定将POCO类映射到表.但是,有时您无法或不想遵守这些约定,需要将实体映射到约定指示外的其他对象,所以Fluent API和注解都是一种方法,这两种方法 ...

  4. KMP算法复习笔记

    KMP 算法 KMP 算法是一种改进的字符串匹配算法,KMP 算法的关键是利用匹配失败后的信息,尽量减少模式串与主串的匹配次数以达到快速匹配的目的.具体实现就是实现一个next()函数,函数本身包含了 ...

  5. Pycharm中Python Console与Terminal的区别

    1.Python Console是Python交互式模式,可以直接输入代码,然后执行,并立刻得到结果 2.Terminal是命令行模式,与系统的CMD(命令提示符)一样,可以运行各种系统命令

  6. CentOS7使用‘中科大源’

    中科大的源质量速度都不错,推荐使用. 这里列出CentOS 7的Base和epel的源. 进入/etc/yum.repos.d/中,将原本的几个repo文件备份,之后新建三个repo文件 内容如下: ...

  7. java的数制转换(详解,全!)

    对于进制转换,c/c++要用到辗转相除,不仅浪费时间,还造成代码量繁多,而任意之间的进制转换还需要以十进制为跳板, 先将其他进制的数字转换为十进制,再将十进制转换为其他进制,而java中自带进制转换的 ...

  8. [Tarjan系列] Tarjan算法与有向图的SCC

    前面的文章介绍了如何用Tarjan算法计算无向图中的e-DCC和v-DCC以及如何缩点. 本篇文章资料参考:李煜东<算法竞赛进阶指南> 这一篇我们讲如何用Tarjan算法求有向图的SCC( ...

  9. OsmocomBB软件实现栈概况

    OsmocomBB软件实现栈概况 简单地说,本文仅描述软件中GSM信号接收到部分. 暂不提及发送流程,引导加载/引导流程,以及各种控制路径特别是从layer1到RF硬件. 首先,通过天线接收RF信号, ...

  10. HashMap - 类注释

    了解到Java8以后HashMap的实现换了,也看了很多博客一直在向我这个小菜鸡说HashMap的重要.因此我决定洗心革面,好好正视HashMap 基于jdk 8 先从类注释开始入手学习,顺便提高提高 ...