1. ping -c1 -W2 If no response is received within 2 seconds, the network is considered unreachable. The default is 5 seconds.
2.seq 2 3 10(echo {2..10..3}) 3 is the step value
3.for num in "/root/bin/*.sh"; do echo the filename is $num; done 支持通配符
4.seq -s + 100 |bc -s specifies that the connection symbol is +
5.if cmd1 &> /dev/null; then if after the judgment, the command can be judged to judge the execution result of the command
6. Using wait in the script, you can exit directly { if ping -c1 -W1 .... fi ; } & done wait wait on a separate line, add
for i in {1..254}; do
{ if ping -c1 -W1 $net.$i &> /dev/null; then
echo $net.$i >> hostlist.txt
fi; } & & means put the execution in the background
done
If wait is not added, you need to enter a carriage return before exiting to the command prompt
7. let i++ returns $? as 1, and let ++i returns $? as 0, so it is safer to use ++i
8.n=10; for i in seq 1 $n
9. eval can first scan to see if there is a variable behind, if there is, it can be replaced with a value, for i in `eval {1..$n}`; there will be a problem without an eval variable
1.color=$[RANDOM%7+31] random color
11.openssl rand -base64 20 | tr -dc '[:alpha:]' |head -c 8
12.echo -e "\033[1;41m \033[0m\033[1;43m \033[0m" print background color (chess background color)
13.while : ; do
echo task
sleep 420
done
while : equivalent to while true
14.kill(killall) -0 httpd can detect whether the service is started successfully -0: indicates signal detection, combined with sleep to specify how many seconds to detect
15.while read line; do ... done </path/to/file
while read -p "Input a number:" num; do echo $num ;sleep 1; done
df | while read disk;do
if $disk |grep "^/dev/sd" > /dev/null; then
usage=`echo $disk |sed -r 's@.* ([[:digit:]]+)%@\1@'`
...
be
done
16.help for can view the usage of for loop, others can use help to view help
17.for ((sum=0,i=1;i<=100;i++)); do
let sum+=i
done
echo sum=$sum
18. Allow Selected Text Blocks
v character oriented
V is row oriented
ctrl-v block oriented
19.PS3="Please choose the menu(1-4):"
select menu in baoyu yanwo renshen jitang; do \
case $menu in
baoyu)
echo $menu price is 1000
break
;;
yanwo)
echo ...
break
;;
*)
esac
done
User input is stored in $REPLY
20.PS2 is the prompt of multi-line redirection, PS1 is the prompt of prompt, PS3 is the prompt of select
PS3="Please choose a number:"
select num in `seq 3`; do
case $num in
1)
echo "Number 1"
;;
2)
echo "Number 2"
;;
3)
echo "Number 3"
;;
esac
done
21.kill -l to view the signal (trap -l)
22.trap 'echo press ctrl+c' int can use 2 instead of int signal
for ((i=0;i<10;i++)); do
echo $i
sleep 0.5
done
trap -p print custom -p
trap '' 2 ignore your ctrl + c
9 The signal cannot be captured and customized, such as trap '' 9, after the definition, you can still use kill -9 to kill the process is invalid
23. The compressed file depends on the suffix, so the suffix must be modified before it can be decompressed, /boot/initramfs... Kernel files need to be modified first, file view type
cpio -tv < file(cpio file type)
cpio -idv
initramfs is an auxiliary driver module file, the simulated file system is more efficient than the simulated disk intrd(centos 5)
24./boot/grub/grub.conf Load the file of the /boot file system. To load the root file system, use initramfs, which is just under /boot
/ The file system needs a driver, and the / driver is under /lib
25.md5sum vmlinuz /boot/vmlinuz Compare the hash value to determine whether the content is the same
26. The vmlinuz file is copied from the CD-ROM file. The initramfs file is generated after the system is installed. Use mkinitrd to generate it.
#mkinitrd /boot/initramfs-`username -r`.img `uname -r`
chroot /mnt/sysimage switch root directory
Execute again # mkinitrd /boot/initramfs-`username -r`.img `uname -r` If the root is not switched, the mkinitrd command cannot be found
sync
sync to disk, just in case
Experiment to repair the damaged /boot/initramfs file
Experiment Delete /boot/vmlinuz file repair method
Delete all files in /boot, excluding directories, repair
rm -f /boot/*