搜索联盟

本文为记录,平时百度或者谷歌搜索的知识点,
这些东西很多都是基础的需要记忆的,
提升效率!

1. maven 阿里云镜像加速配置

1
2
3
4
5
6
7
vim /etc/maven/settings.xml
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

2. 将shell的if缩写到一行

1
2
3
4
[[ ! -d /data ]] && mkdir /data -pv 
# 如果目录不存在则创建文件
#或者
if [ 0 -eq $? ]; then echo "命令执行成功"; else echo "命令执行失败"; fi

3. systemd配置文件

systemd 配置文件存在于以下三个文件夹中:

  1. /etc/systemd/system 存放系统启动的默认级别及启动的unit的软连接,优先级最高。
  2. /run/systemd/system,系统执行过程中产生的服务脚本,优先级次之。
  3. /usr/lib/systemd/system 存放系统上所有的启动文件。优先级最低
    Ubuntu 18.4 发现在/lib/systemd/system/下,
    发现方法: find / -name ssh.service

4. echo颜色

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@k8s-node02 test]# echo -e "\e[30m test content黑 \e[0m"
test content黑
[root@k8s-node02 test]# echo -e "\e[31m test content红 \e[0m"
test content红
[root@k8s-node02 test]# echo -e "\e[32m test content绿 \e[0m"
test content绿
[root@k8s-node02 test]# echo -e "\e[33m test content黄 \e[0m"
test content黄
[root@k8s-node02 test]# echo -e "\e[34m test content蓝 \e[0m"
test content蓝
[root@k8s-node02 test]# echo -e "\e[35m test content紫 \e[0m"
test content紫
[root@k8s-node02 test]# echo -e "\e[36m test content天蓝 \e[0m"
test content天蓝
[root@k8s-node02 test]# echo -e "\e[37m test content白 \e[0m"
test content白

5. set -eux

set -eux一般使用在linux脚本中
作业:以调试的方式执行shell,只识别定义过的变量,同时脚本传回值非0,直接结束shell。

6. cp执行命令,如何直接覆盖不提示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@VM_145_128 ~]# alias cp
alias cp='cp -i'

1、永久关闭当前用户下的cp别名配置

sed -i "s/alias cp='cp -i'/#alias cp='cp -i'/g" ~/.bashrc

source ~/.bashrc


2、屏蔽当前命令使用别名

[root@VM_166_132 ~]# cat test1.txt
ddddddd
[root@VM_166_132 ~]# \cp -f test.txt test1.txt
[root@VM_166_132 ~]# cat test1.txt
test1

7. Navicat一点击菜单栏就停止工作

关闭有道词典的屏幕取词功能

8. mysql唯一索引

创建唯一索引的目的不是为了提高访问速度,而只是为了避免数据出现重复。唯一索引可以有多个但索引列的值必须唯一,索引列的值允许有空值。如果能确定某个数据列将只包含彼此各不相同的值,在为这个数据列创建索引的时候就应该使用关键字UNIQUE把它定义为一个唯一索引。

9. grep 不区分大小写

grep -i

10. 如何排除第一行显示?

1
2
3
4
5
6
7
8
9
10
# tail
cat 123.txt |tail -n +2
## +2 表示从第二行开始显示,包括第二行

# awk
awk 'NR!=1 { print }' 123.txt

# sed
sed -n '1!p' 123.txt
## n! 表示不需要打印的行

11. 判断变量不存在

1
2
3
4
5
6
ip=$(ip addr|sed -nr 's#^.*inet (.*)/24.*$#\1#gp')
if [ ! $ip ];then
echo "not ok"
else
echo "ok"
fi

12. Shell中去除字符串前后空格的方法

参考文档

1
2
3
4
5
# 简单命令
#eval过滤
eval echo " A BC "
# awk过滤
echo " A BC "|awk '$1=$1'

13. 将字符串中的多个空格替换成一个空格

1
2
3
#
tr -s ' '
## -s 删除所有重复出现字符序列,只保留第一个;即将重复出现字符串压缩为一个字符串。

14. bash 字符串重复

1
2
3
4
5
6
7
8
9
#!/bin/bash

for i in `seq 1 4`
do
A="$A!"
A="$A"
echo $A
done
~
---------------- 谢谢光临 ----------------

本文标题:搜索联盟

文章作者:pxrux

发布时间:2020年11月03日 - 00:11

最后更新:2020年11月03日 - 00:11

原始链接:http://www.mykernel.cn/baidu_google.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

0%