Linux 第22天: (09月20日) 練習和做業

Linux 第22天: (09月20日) 練習和做業linux

 

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


awk 'BEGIN{print 10*10}'bash

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

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

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
ide

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

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

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行
ci

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

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 -rdfvim /boot/grub2/grub.cfg刪除相應menuentrycd /bootrm *3.18* -fcd /lib/moduleslsrm -rf 3.18.41-1.0-wanglinux/cd /usr/srcrm -rf linux-3.18.41/rm linuxls

相關文章
相關標籤/搜索