Linux 第22天: (09月20日) 练习和作业

 

awk -F: '{printf "usr:%-20s === uid:%-10.2d\n",$1,$3}' /etc/passwd


awk 'BEGIN{print 10*10}'

awk -v i=1 'BEGIN{print i++,i}'

awk -v i=1 'BEGIN{print ++i,i}'

awk '$0~"root"{print $0}' /etc/passwd
awk -F: '$1~"root"' /etc/passwd   包含
awk -F: '$1~/root/' /etc/passwd   包含
awk -F: '$1=="root"' /etc/passwd  等于
awk -F: '$1==/root/' /etc/passwd  等于
awk -F: '{$3>=1000?username="commonuser":username="sysuser";printf "%s %s %d\n", username,$1,$3}' /etc/passwd

awk '/^UUID/{print $1}' /etc/fstab 行首
awk '/bash$/{print $0}' /etc/passwd 行尾

awk '""{print $0}' /etc/passwd 空,假
awk '0{print $0}' /etc/passwd 空,假
awk 'i=0{print $0}' /etc/passwd 空,假
awk '" "{print $0}' /etc/passwd 非空,真

awk 'j=0;i=1{print i,j}' /etc/passwd
awk '{j=0;i=1}{print i,j}' /etc/passwd
awk '!0' /etc/fstab
awk -F: '$NF~/bash$/' /etc/passwd 包含bash
awk -F: '$NF=="bash"' /etc/passwd 匹配bash
awk -F: '/^root\>/,/^ftp\>/' /etc/passwd  从root到ftp
awk -F: 'NR>=10 && NR<=20' /etc/passwd 从10行道20行

awk -F: 'BEGIN{print "username uid"}{print $1,$3}' /etc/passwd

seq 10 |awk 'i=!i' 显示奇数行
seq 10 |awk 'i=!i{print $0}'
seq 10 |awk '!(i=!i)' 显示偶数行
seq 10 |awk -v i=0 'i=!i' 奇数行
seq 10 |awk -v i=1 'i=!i' 偶数行

awk -F: '{if($3<100){print $1,$3}else if ($3>=100 && $3<1000){print $1,$3}else {print $1,$3}}' /etc/passwd


awk '/^[[:space:]]+linux16/{i=1;while(i<=NF){print $i,length($i)};i++}' /etc/grub2.cfg
awk 'BEGIN{total=0;i=0;do{total+=i;i++}while(i<=100);print total}' 累加100
for i in `seq 100`; do let sum+=i;done;echo $sum  累加100
seq -s "+" 100|bc
sum=0;for((i=1;i<=100;i++));do let sum+=i; done; echo $sum

time (awk 'BEGIN{total=0;i=0;do{total+=i;i++}while(i<=100);print total}')
time (for i in `seq 100`; do let sum+=i;done;echo $sum)
time (sum=0;for((i=1;i<=100;i++));do let sum+=i; done; echo $sum)


awk 'BEGIN{sum=0;for(i=1;i<=100;i++){if(i%2==0) countinue;sum+=i}print sum}' 偶数总和
awk 'BEGIN{sum=0;for(i=1;i<=100;i++){if(i%2==0){countinue}sum+=i}print sum}' 偶数总和
awk 'BEGIN{sum=0;for(i=1;i<=100;i++){if(i%2!=0){countinue}sum+=i}print sum}' 奇数总和


awk -F: '{if($3%2!=0) next; print $1,$3}' /etc/passwd 显示UID偶数行
awk -F: '{if(NR%2!=1) next; print $1,$3}' /etc/passwd 显示偶数行

awk 'BEGIN{week["first"]="sun";week[1]="mon";print week[1]}'

awk '{!array[$0]++}' file 去掉重复行
awk '{!array[$0]++;print $0,array[$0]}' f1

awk 'BEGIN{ week["first"]="sun";week[2]="mon";for(i in week){print week[i]}}'

 

 

 

 

 

 

 


cd /usr/lib/systemd/system 每个服务启动脚本 类似/etc/init.d/
cd /run/systemd/system 系统产生
cd /etc/systemd/system 管理员存放 类似/etc/rc.d/rcN.d/Sxx

systemctl -t help 列出unit可用类型
cd /usr/lib/systemd/system
ls *socket
cat sshd.socket
cd /var/spool/at/
cd /var/spool/mail/
cd /var/spool/cron/
ls *.path


ll /etc/systemd/system/httpd.service
rm /etc/systemd/system/httpd.service
systemctl stop httpd
systemctl mask httpd         禁止手动或自动启动
systemctl start httpd
systemctl umask httpd                删除软连接
ll /etc/systemd/system/httpd.service
systemctl start httpd
systemctl is-active httpd
systemctl list-units -t service      查看活动
systemctl list-units -t service -a   查看所有
ls /usr/lib/system/system/*.service |wc -l 有252个
systemctl list-units-files -t service -a   有262个

systemctl is-enabled httpd
systemctl enable httpd
rm -f /etc/systemd/systemd/multi-user.target.wants/httpd.service
systemctl is-enabled httpd
systemctl enable httpd
systemctl is-enabled httpd
systemctl disable httpd
ls /etc/systemd/system/*.wants/sshd.service
ls /etc/systemd/system/*.wants/httpd.service


systemctl list-dependencies httpd.service
systemctl list-units -t service -a
systemctl list-units-files -t service -a
systemctl status sshd -l
systemctl --failed --type=service
systemctl start httpd

 

ls /usr/lib/systemd/system/*.target
systemctl list-dependencies graphical.target

cat /etc/inittab
runlevel
systemctl get-default
systemctl set-default multi-user
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target
to /usr/lib/systemd/system/multi-user.target.
ll /etc/systemd/system/default.target
rm -f /etc/systemd/system/default.target
ln -s /usr/lib/systemd/system/graphical.target
/etc/systemd/system/default.target

cat /usr/lib/systemd/system/graphical.target
cat /usr/lib/systemd/system/multi-user.target
runlevel
init 3
systemctl isolate graphical.target 切换到5级别
systemctl list-units --type target
systemctl list-dependencies rescue.target
cd /misc/cd
df
cd /etc/rc.d
systemctl list-dependencies emergency.target
systemctl rescue
systemctl list-units-t target
systemctl isolate graphical.target
which init
ll `which init`
ll `which poweroff`
cat /etc/rc.d/rc.local 存在但不推荐用于7版本
cd /etc/rc.d
cd /usr/lib/systemd/system
cat httpd.service
vim httpd.service
systemctl status httpd
vim sshd.socket
vim sshd.service

cd /etc/systemd/system/
vim bak.service
vim bak.sh
tar Jcf /testdir/etc`date +%F`.tar.xz /etc/ &> /dev/null
chmod +x /testdir/bak.sh
systemctl list-units -t service
systemctl daemon-reload
systemctl list-units -t service
systemctl list-unit-files -t service
systemctl start bak
ls /testdir/ -l

改密码
grub启动界面按键e
linux16行之后加入
systemd.unit=multi-user.target 多用户
rd.break 单用户
按键ctrl+x结束
pwd
ls
mount
mount -o remount,rw /sysroot
chroot /sysroot/
ls
passwd
touch /.autorelabel
exit
exit


修改grub菜单默认内核
cat /boot/grub2/grub.cfg
vim /etc/default/grub
GRUB_DEFAULT=0
grub2-mkconfig > /boot/grub2/grub.cfg
cat /boot/grub2/grub.cfg


删除手工编译安装的内核
uname -r
df
vim /boot/grub2/grub.cfg
删除相应menuentry
cd /boot
rm *3.18* -f
cd /lib/modules
ls
rm -rf 3.18.41-1.0-wanglinux/
cd /usr/src
rm -rf linux-3.18.41/
rm linux
ls