Linux命令实战(三)
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命令实战(三)的更多相关文章
- Java开发人员必须掌握的Linux命令(三)
做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开! 学习应该是快乐的,在这个乐园中我努力让自己能用简洁易懂(搞笑有趣)的表达来讲解知识或者技术,让学习之旅充满乐趣,这就是写博 ...
- Linux命令实战(一)
1.pwd(printing working directory)打印当前工作目录路径 [root@test sysconfig]# pwd /etc/sysconfig 2.ls(list)列出当前 ...
- Linux命令实战(四)
1.Linux上的文件管理类命令都有哪些,其常用的使用方法及相关示例演示. 文件或目录的新建 touch :将每个文件的访问时间和修改时间修改为当前时间.若文件不存在将会创建为空文件,除非使用-c或- ...
- Linux命令(三)vim编辑器的常用命令
.subTitle { background: rgba(51, 153, 0, 0.53); border-bottom: 1px solid rgba(0, 102, 0, 1); border- ...
- linux命令基础三
使用cat命令进行文件的纵向合并使用cat命令实现文件的纵向合并: 例如:使用cat命令将baby.age.baby.kg和baby.sex这三个文件纵向合并为baby文件的方法:cat baby.a ...
- Linux命令实战(五)
1.显示/etc目录下,以非字母开头,后面跟了一个字母以及其他任意长度字符的文件或目录. [qiuhom@test ~]$ls -d /etc/[^[:alpha:]][[:alpha:]]* ls: ...
- Linux命令-文件管理(三)
Linux more命令 Linux more 命令类似 cat ,不过会以一页一页的形式显示,更方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会往回(bac ...
- Linux命令第三篇
作业三: 以操作文件的方式,新建一个用户alex echo "alex:x:1200:1200::/home/alex/:/bin/bash" >> /etc/pass ...
- 50个常用的Linux命令(三)基础实例
ls ls -als -l == llls -Aldrwxrwxrwx. 2 root root 6 Dec 21 20:38 Videos-rwxrwxrwx 1 root ...
随机推荐
- 基于STM32F1与NRF24L01模块的SPI简单通信
一.前言 1.简介: 本文是基于STM32F1,将数据发送至NRF模块的寄存器,并将数据重新读取,通过串口发送出来的简单SPI单通信. 2.SPI简介: 调过STM8的都已经对SPI有所了解,调法都一 ...
- PHP list的赋值
List右边的赋值对象是一个以数值为索引的数组,左边的变量的位置和赋值对象的键值一一对应,有些位置的变量可以省略不写.非末尾的被赋值变量省略时,分隔的逗号不能省略.左边变量被赋值的顺序是从右到左的. ...
- redis之Scan
scan 相比keys 具备有以下特点:1.复杂度虽然也是 O(n),但是它是通过游标分步进行的,不会阻塞线程;2.提供 limit 参数,可以控制每次返回结果的最大条数,limit 只是一个 hin ...
- 百万年薪python之路 -- 文件操作
1.文件操作: f = open("zcy.txt" , mode="r" , encoding="UTF-8") open() 打开 第一 ...
- 保存为txt
打开对话框保存为txt #region this.dDownTable = (DataTable)(this.dg1.DataContext); ) { string fName = string.E ...
- 不想用锐捷怎么办?锐捷出问题|锐捷不能用怎么办?用menohust代替吧
首先获取 MentoHUST(代替锐捷网络认证客户端) V4.1.0.2001 绿色免费版 解压到任意目录 用管理员身份 启动 安装&卸载 .bat(右键用管理员运行) 这个文件可能乱码了 ...
- django-URL转换器(四)
接URL匹配那一节. 在book中的urls.py from django.urls import path from . import views urlpatterns = [ path('', ...
- fenby C语言 P18
#include <stdio.h> int main(){ int i; for(i=1;i<=15;i++) { if((i%2==1)) { printf("%d\n ...
- incompatible implicit declaration of built-in function 'fabs'
形如: float a = -3.0; float b = fabs(a); 形参数据类型和实参数据类型完全一致,却还报警告: incompatible implicit declaration of ...
- 使用uni-app开发微信小程序
uni-app 开发微信小程序 前言 9月份,开始开发微信小程序,也曾调研过wepy/mpvue,考虑到后期跨端的需求,最终选择使用了uni-app,本文主要介绍如何使用uni-app搭建小程序项目, ...