1.查看硬件参数
$ cat /etc/centos-release #version
$ lspci | grep -i nvidia #gpu
$ uname -a #kernel
$ lshw -html > /hardware.html #print all info
$ lscpu #cpu info
$ cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c #cpu parameters
$ cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l #physical cpus
$ cat /proc/cpuinfo| grep "cpu cores"| uniq #no.cores
$ cat /proc/cpuinfo| grep "processor"| wc -l #virtual cpus
$ cat /proc/meminfo |grep MemTotal #memory
$ fdisk -l |grep Disk #disk info
$ lsscsi #SSD
$ lsof -i #list the process name and number that has opened the ports
$ netstat -tulnp #see if a program or process is listening on a port, ready to accept a packet
2.切换节点模式
$ systemctl get-default #check, graphical.target is usually not useful
$ systemctl stop gdm.service
$ systemctl set-default multi-user.target
3.清理buffers/cache
#to clear the swap
$ swapoff /dev/dm-1
$ swapon /dev/dm-1
$ swapon -s
4.Yum安装
$ yumdownloader packagename #off-line install
$ yum --disablerepo='*' install rpm-package
5.同步时间
#on master node
$ date -s "2022-11-22 13:15:43"
$ clock -w
$ systemctl restart ntpd.service
# wait for a while
# on slave node
$ systemctl stop ntpd.service
$ ntpd -gq
$ systemctl start ntpd.service
6.文件操作
#Permission
$ chmod -R 700 ./file
$ chown -R user:group ./file
#Move
# copy all the files including hidden files
$ cp -a /old/. /folder/
#Download
# background, continue, input, output
$ wget -bc -i url.list -o log.txt
#advanced options:
-r #recursive
-np #no-parent
-4 #connect only to IPv4 addresses.
#write output to a file named as the remote file
$ curl -O http://file
#Compress & uncompress
$ tar -zxvf file -C /dir # -C uncompress to directory //-z for gzip //-j for bzip
$ unzip file -d ./dir # -d uncompress to directory
$ tar -cfz archive.tar.gz file1 file2 file3
$ tar -czPf archive.tar.gz /file_dir -C /outdir # -P don't strip leading `/'s from file names
7.日志记录
$ echo 'HISTTIMEFORMAT="%F %T "' >> /etc/profile
$ source /etc/profile
8.备份
$ rsync -zvh backup.tar /tmp/backups/ #cp file
$ rsync -avzh /root/rpmpkgs /tmp/backups/ #cp dir
$ rsync --remove-source-files -avzhR /root/rpmpkgs /tmp/backups/ #remove source
9.MD5校验
$ find ./ -type f -print0 | xargs -0 md5sum >> filename.md5
$ md5sum -c filename.md5 > check.log
10.任务管理
$ ps -u <username>
$ kill -9 <PID>
11.快捷处理文件
1)for循环
$ for i in {a..b};do ...;done
$ for i in `cat file.list`;do ...;done
2)查看文件行列数
$ wc -l a.txt
$ cat a.txt | awk '{print NF}'
3)按某列排序
$ sort -n -k1
4)转置
$ awk '{for(i=1;i<=NF;i++){if(NR == 1){a[i]=$i;}else{a[i]=a[i]""$i;}}}END{for(i=1;a[i]!="";i++){print a[i];}}' a.txt
5)大小写转换
$ cat a.txt | tr a-z A-Z > b.txt
6)删除重复行
$ sort -n a.txt | uniq
$ awk '!x[$0]++' a.txt
7)删除含有关键词的行
$ sed -e '/xxx/d' file
8)查找某项符合关键词的行
$ awk '$1=="xxx" {print $0}' file
9)取某行到最后一行
$ cat file | tail -n +2
$ cat file | sed -n '2,$p'
10)取除了某行/列的其他所有内容
$ awk '{if(NR!=1) print }' file
$ cut -f1 --complement file
11)每行乘以一个值
$ cat a.txt | awk "{print \$1 * 100}"
12)每行加前缀/后缀
$ sed 's/^/Head&/g' a.txt > b.txt
$ sed 's/$/&Tail/g' a.txt > b.txt
13)查找两列的相同与不同
$ grep -Ff file1 file2
$ grep -vFf file1 file2 #in file2 but not in file1
14)求最大值、最小值、平均值、和
$ cat a.txt|awk 'BEGIN{max = 0} {if ($1+0>max+0) max=$1 fi} END{print "Max=", max}'
$ cat a.txt|awk 'BEGIN{min = 65536} {if ($1+0<min+0) min=$1 fi} END{print "Min=", min}'
$ cat a.txt|awk '{sum+=$1} END{print "Avg=", sum/NR}'
$ cat a.txt|awk '{sum+=$1} END{print "Sum =", sum}'
15)替换
$ sed -i 's/origin/new/g' file
16)指定符号连接
$ paste -d: a.txt b.txt > c.txt
17)删除^M字符
$ cat a.txt | tr -d "\r" > b.txt
待续...