- A+
所属分类:linux技术
1.用vmware添加一块10G的硬盘,且永久挂载到/data01中,写出详细的步骤
2.用自己语言描述raid0和raid1的区别
RAID 0: 将两个或以上相同信号,容量的硬盘组合,磁盘阵列的总容量是多个硬盘的总和,数据依次写 入物理磁盘,理想状态下,硬盘读写性能会翻倍。但只要坏一块磁盘,所有数据都会损坏 优点:速度快 缺点:冗余差 RAID 1: RAID 1 技术,是将两块以上硬盘绑定,数据写入时,同时写入多个硬盘,因此即使有硬盘故障,也有数据备份。 优点:冗余性好 缺点:浪费资源
3.sed删除文件的空白和注释行
[root@vm-main luffty]# cat test.txt I am oldboy teacher I teach linux. #I like python. My qq is 877348180. My name is chaoge. #My website is http://pythonav.cn [root@vm-main luffty]# cat test.txt | sed '/^$/d' | sed '/^#/d' I am oldboy teacher I teach linux. My qq is 877348180. My name is chaoge. [root@vm-main luffty]# sed -e '/^$/d' -e '/^#/d' test.txt I am oldboy teacher I teach linux. My qq is 877348180. My name is chaoge.
4.使用awk删除文件chaoge.txt空白行
[root@vm-main luffty]# cat test.txt | awk '!/^$/{print $0}' I am oldboy teacher I teach linux. #I like python. My qq is 877348180. My name is chaoge. #My website is http://pythonav.cn
5.把命令echo "I am oldboy" 的结果写入"黑洞文件中",且命令的标准错误输出,也当做标准输出处理
echo "I am oldboy" > /dev/null 2>&1
6.利用{}符号备份/etc/hosts文件
[root@vm-main luffty]# cp /etc/hosts{,.bak} [root@vm-main luffty]# ll /etc/ | grep hosts -rw-r--r--. 1 root root 158 Jun 7 2013 hosts -rw-r--r--. 1 root root 370 Jun 7 2013 hosts.allow -rw-r--r-- 1 root root 158 Sep 28 04:26 hosts.bak -rw-r--r--. 1 root root 460 Jun 7 2013 hosts.deny [root@vm-main luffty]#
7.过滤掉文件chaoge.txt的注释和空白行
[root@vm-main luffty]# cat test.txt | grep -Ev '(^$|^#)' I am oldboy teacher I teach linux. My qq is 877348180. My name is chaoge. [root@vm-main luffty]# cat test.txt | grep -v '^$' | grep -v '^#' I am oldboy teacher I teach linux. My qq is 877348180. My name is chaoge.
8. 找出除了小写字母以外的字符,文本如下chaoge.txt
I am oldboy teacher
I teach linux.
I like python.
My qq is 877348180.
My name is chaoge.
My website is http://pythonav.cn
[root@huahua-centos7-aliyun luffy]# cat a.txt | sed 's/[a-z]//g' I I . I . M 877348180. M . M ://. [root@huahua-centos7-aliyun luffy]# cat a.txt | grep -Eo '[^a-z]'
9.使用sed输出文件chaoge.txt的2-5行内容
[root@vm-main luffty]# cat -n chaoge.txt | sed -n '2,5p'
2 I teach linux. 3 I like python. 4 My qq is 877348180. 5 My name is chaoge.
10.使用sed删除含有game字符的行,chaoge.txt
[root@vm-main luffty]# cat chaoge.txt I am oldboy teacher I teach linux. I like python. My qq is 877348180. My name is chaoge. My website is http://pythonav.cn I like play game [root@vm-main luffty]# cat chaoge.txt | sed '/game/d' I am oldboy teacher I teach linux. I like python. My qq is 877348180. My name is chaoge. My website is http://pythonav.cn
11.使用sed替换文件chaoge.txt中,替换所有My为His,同时换掉QQ号为8888888
My name is chaoge.
I teach linux.
I like play computer game.
My qq is 877348180.
My website is http://pythonav.cn.
[root@vm-main luffty]# cat chaoge.txt2 | sed -e 's/My/His/g' -e 's/877348180/8888888/' His name is chaoge. I teach linux. I like play computer game. His qq is 8888888. His website is http://pythonav.cn. [root@vm-main luffty]#
12.用sed取出ip地址
[root@vm-main luffty]# ifconfig ens33 | sed -n '2p' | sed -n 's/^.*inet//p' | sed -n 's/netmask.*$//p' 192.168.58.130
13.用awk显示/etc/passwd文件的第一列,倒数第二列,以冒号分割。
[root@vm-main luffty]# cat /etc/passwd | awk -F ":" '{print $1":"$(NF-1)}' root:/root bin:/bin daemon:/sbin adm:/var/adm lp:/var/spool/lpd sync:/sbin shutdown:/sbin halt:/sbin mail:/var/spool/mail operator:/root games:/usr/games ftp:/var/ftp nobody:/ systemd-network:/ dbus:/ polkitd:/ postfix:/var/spool/postfix sshd:/var/empty/sshd test:/home/test abrt:/etc/abrt saslauth:/run/saslauthd pcp:/var/lib/pcp mailnull:/var/spool/mqueue smmsp:/var/spool/mqueue apache:/usr/share/httpd tss:/dev/null mailman:/usr/lib/mailman [root@vm-main luffty]# cat /etc/passwd | awk -v OFS=":" -F ":" '{print $1,$(NF-1)}' root:/root bin:/bin daemon:/sbin adm:/var/adm lp:/var/spool/lpd sync:/sbin shutdown:/sbin halt:/sbin mail:/var/spool/mail operator:/root games:/usr/games ftp:/var/ftp nobody:/ systemd-network:/ dbus:/ polkitd:/ postfix:/var/spool/postfix sshd:/var/empty/sshd test:/home/test abrt:/etc/abrt saslauth:/run/saslauthd pcp:/var/lib/pcp mailnull:/var/spool/mqueue smmsp:/var/spool/mqueue apache:/usr/share/httpd tss:/dev/null mailman:/usr/lib/mailman
14.用awk取出ip地址
[root@vm-main luffty]# ifconfig ens33 | awk 'NR==2 {print $2}' 192.168.58.130
15.用awk找出/etc/passwd文件中禁止登录的用户
[root@vm-main luffty]# cat /etc/passwd | awk -F ":" '$NF=="/sbin/nologin"{print $1}' bin daemon adm lp mail operator games ftp nobody systemd-network dbus polkitd postfix sshd abrt saslauth pcp mailnull smmsp apache tss mailman