更改Linux终端中用户名颜色
用户名的设置在~下.bashrc
文件中,更改PS1变量的值,如果没有就自己加一行
PS1='\[\e[32m\][\u@\h \W]#\[\e[m\] '
PS1="\[\e[1;32m\][\t \[\e[1;33m\]\u\[\e[35m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\$ "
32代表的是绿色前景色,\[\e[m\]
是关闭颜色设置,如果没有这一句,后面所有的字符都会是前面设置的颜色。
颜色设置在bash脚本中是通用的,也就是说你可以在终端里直接输入
前景代码 | 背景代码 | 颜色 |
---|---|---|
30 | 40 | 黑色 |
31 | 41 | 红色 |
32 | 42 | 绿色 |
33 | 43 | 黄色 |
34 | 44 | 蓝色 |
35 | 45 | 紫红 |
36 | 46 | 青蓝 |
37 | 47 | 白色 |
1 | 1 | 透明 |
Linux比较数字大小
你可以使用比较运算符来比较数字。以下是一些常见的比较运算符:
字符 | 含义 |
---|---|
-eq | 等于 |
-ne | 不等于 |
-lt | 小于 |
-le | 小于等于 |
-gt | 大于 |
-ge | 大于等于 |
输出时间只包括年月日时分秒
date +%Y-%m-%d\ %H:%M:%S
Linux中求百分率
numerator=75
denominator=100
# 使用 bc 进行除法计算和百分率转换
percentage=$(echo "scale=2; $numerator / $denominator * 100" | bc)
# 使用 printf 格式化输出百分率
printf "Percentage: %.2f%%\n" $percentage
命令详解:
神奇的光盘挂载目录
rpm -q autofs || yum -y install autofs
systemctl enable --now autofs
查看生成文件
ls /misc/cd
centos8停止维护修改 yum 源
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
mysql操作
修改用户密码
alter user root@'localhost' identified by 'password';
持久修改mysql提示符
[root@sre-5 ~]# cat /etc/my.cnf.d/mysql-clients.cnf
[mysql]
prompt="\\r:\\m:\\s(\\u@\\h) [\\d]>\\_"
效果如下图所示
update语句修改数据
注意:一定要有显示条件,否则将修改所有行为指定字段
可利用mysql选项避免这个错误:
mysql -U | --safe-updates| --i-am-a-dummy
[root@sre-5 ~]# vim /etc/my.cnf
[mysql]
safe-updates
源码安装jdk1.8 配置相关文件
首先下载有关的安装包:jdk-8-oracle
解压安装包至usr/local/jdk
tar -xvf jdk-8u381-linux-x64.tar.gz -C /usr/local/jdk
编辑 /etc/profile
文件
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_381
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
使用 source
命令让配置生效
source /etc/profile
验证:
root@ubuntu:~# java -version
java version "1.8.0_381"
Java(TM) SE Runtime Environment (build 1.8.0_381-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.381-b09, mixed mode)
root@ubuntu:~# javac
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user class files and annotation processors
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-proc:{none,only} Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
-processorpath <path> Specify where to find annotation processors
-parameters Generate metadata for reflection on method parameters
-d <directory> Specify where to place generated class files
-s <directory> Specify where to place generated source files
-h <directory> Specify where to place generated native header files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-profile <profile> Check that API used is available in the specified profile
-version Version information
-help Print a synopsis of standard options
-Akey[=value] Options to pass to annotation processors
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
-Werror Terminate compilation if warnings occur
@<filename> Read options and filenames from file
Linux命令随机生成16位数字字母大小写组合
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1
Ubuntu在更新软件源包报错未签名
The repository ‘http://pkg.jenkins.io/debian-stable binary/ Release’ is not signed.
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5BA31D57EF5975CA