1、取出IP地址1.ifconfig eth0|grep "inet addr"|cut -d":" -f2|cut -d" " -f1
2.ifconfig eth0|grep "inet addr"|awk -F ":" '{print $2}'|awk '{print $1}'
3.ifconfig eth0|grep "inet addr"|awk -F "[: ]" '{print $13}'
4.ifconfig eth0|grep "inet addr"|awk -F "[: ]+" '{print $4}'
5.ifconfig eth0|sed -n '2p'|awk -F "[: ]+" '{print $4}'
6.ifconfig eth0|awk -F "[: ]+" 'NR==2{print $4}'
7.ifconfig eth0|sed -n '/inet addr/p'|sed 's#^.*addr:##g'|sed 's# Bc.*$##g'
8.ifconfig eth0|sed -n 's#^.*addr:\(.*\) Bcast.*#\1#gp'
2、查找当胆目录下所有文件,并把文件中的test.com字符串,替换成123.com。拓展-插入数据:sed -i '1 i test' test.txt //表示在第1行插入,test
1.find . -type -f -exec sed -i 's#test\.com#123\.com#g' {} \;
2.find . -type -f|xargs sed -i 's#test\.com#123\.com#g'
3、请问在echo命令上加什么参数可以实现下面命令在同一行输出。echo "test";echo "test2"
1.echo -n echo "test";echo "test2"
2.echo -e "test\ntest2"
4、请给出如下格式的date 命令:18-03-31.再给出实现周输出,比如:周六输出为6 ,请分别给出命令。date '+%y-%m-%d'
date +%F|cut -c 3-
date '+%Y-%m-%d'|cut -c 3-
date '+%w' //输出星期几
date '+%u' //输出星期几
date +%Y-%m-%d\ %H:%M:%S //年月日 时分秒
date ++%F\ %T //年月日 时分秒
date +%F -d '3 day' //3天后
date +%H -d '3 hour' //3小时后
date +%M -d '3 min' //3秒后
拓展:
以时间命名打包文件。
tar -zcvf test-$(date +%F).tar.gz ./test
tar -zcvf test.tar.gz ./test //test目录打包为test.tar.gz
tar -tf test.tar.gz //查看压缩包内容
tar -zcvf test-$(date +%F -d '-7 day').tar.gz ./test //打包7天前的压缩包
5、已知 :/test/test.txt 文件内容为如下,把空行过滤掉。test1
abcd2
mnbm31.grep -v "^$" /test/text.txt
2.sed /^$/d/ /test/text.txt
3.awk /^[^$]/ /test/text.txt
6、已知 :/test/test.txt 文件内容为如下,把空行过滤掉。赞0
踩0
本文标签:习题
版权声明:若无特殊注明,本文为《橙子柠檬》原创,转载请保留文章出处。
本文链接:https://qinzc.me/post-64.html
正文到此结束