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 ...
随机推荐
- 各种常见文件的hex文件头
我们在做ctf时,经常需要辨认各种文件头,跟大家分享一下一些常见的文件头. 扩展名 文件头标识(HEX) 文件描述 123 00 00 1A 00 05 10 04 Lotus 1-2-3 spr ...
- drf框架接口文档
drf框架接口文档 REST framework可以自动帮助我们生成接口文档. 接口文档以网页的方式呈现. 自动接口文档能生成的是继承自APIView及其子类的视图. 一.安装依赖 pip insta ...
- Linux系统取证实践
目录 0x00 本课概述 0x01 用到命令 0x00 本课概述 本课时学习Linux系统下取证分析命令. 0x01 用到命令 1.top命令 2.ps命令 3.kill命令 4.linux系统日 ...
- 后台模板引擎ejs与前台模板引擎artTemplate的简单介绍
动态网页是指前端页面当中的数据内容来源于后台数据库,前端的html代码会随着后台数据的变化而变化,是动态生成的.制作动态网页有两种方式,一种方式是在后台拿到前端的html模板,利用后台模板引擎(如ej ...
- springboot Jar包 部署到Linux服务器运行脚本
1.jar包同级目录 , 如下: #!/bin/sh RESOURCE_NAME=demo.jar tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep ...
- 告别硬编码,mysql 如何实现按某字段的不同取值进行统计
上周我突然意识到,我在grafana上写的 sql 语句存在多处硬编码.这篇笔记将记录如何实现没有硬编码的sql语句,以及自学编程过程中如何应对自己的笨拙代码和难题不断的状况. 1.有效但粗笨的硬编码 ...
- Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials
原文链接:Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials Sentinel Getting Sta ...
- java.lang.OutOfMemoryError GC overhead limit exceeded原因分析及解决方案
最近一个上线运行良好的项目出现用户无法登录或者执行某个操作时,有卡顿现象.查看了日志,出现了大量的java.lang.OutOfMemoryError: GC overhead limit excee ...
- 刷14道leetcode的总结
引子 为什么我要刷leetcode?换工作?不是!那是?玩!巴菲特的双目标清单系统,基本方法是列两个清单,一个是职业生涯最重要的目标(不超过5个),另一个是比较重要的目标.对于比较重要的目标,要像躲避 ...
- 自己动手破解Z.EntityFramework.Extensions 4.0.11.0的方法
因为项目中使用到Z.EntityFramework.Extensions 和 Z.EntityFramework.Plus(免费开源)两个类库,但是Z.EntityFramework.Extensio ...