常用命令
find . -name "*.txt" -type f -print 打印当前目录及其子目录下的txt文件路径
. : 表示在当前目录下.
-name "*.txt" :表示查找所有后缀为txt的文件.
-type f:表示文件类型为一般正规文件.
-print:表示将查询结果打印到屏幕上.
find . -name "*.txt" -type f -print -exec rm -rf {} \; 删除前面打印出来的文件
-exec command :command为其他命令,-exec后可再接其他的命令来处理查找到的结果,上式中,{}表示”由find命令查找到的结果“,find所查找到的结果放置到{}位置,-exec一直到”\;“是关键字,表示find额外命令的开始(-exec)到结束(\;),这中间的就是find命令的额外命令,上式中就是 rm -rf.
python -m SimpleHTTPServer 8888 python启动http服务
tar czvf test.zip my-work/ 将my-work目录压缩为test.zip
tar zxvf test.zip 解压test.zip到当前目录,解压出来为my-work文件夹
git rebase参考
https://blog.csdn.net/itfootball/article/details/44154121
mvn clean install -Dmaven.test.skip=true
创建软链接
sudo ln -s /opt/taobao/install/maven-3.2.5/ /opt/taobao/maven
修改软链接
ln -snf 【新目标目录】 【软链接地址】
清空文件内容
[log@xxxx-40-5034 /home/log/logs/xxxx]
$> xxxx-task.log
安装深度应用商店
sudo apt install deepin-appstore
启动jar包执行,将日志重定向到log文件,并且在后台执行
java -jar /home/api/xxxx-0.0.1-SNAPSHOT.jar >/home/api/logs/nohup.log 2>&1 &
按应用名杀进程
ps aux | grep Intelligent| grep -v auto | awk '{print $2}' | xargs kill -9
解压缩超大ZIP文件,unzip命令报错
7za x xxx.zip
https://blog.csdn.net/u013911720/article/details/39935983/
压缩/解压缩
sudo tar -zxvf apache-zookeeper-3.7.0-bin.tar.gz -C /usr/lib/zookeeper
unzip xxx.zip
修改文件权限
chmod -R a+r *
### 给所有用户加上指定文件的写权限
sudo chmod a+w sources.list
新建用户
#### 新建admin用户
sudo useradd admin
#### 设置admin用户的密码
sudo passwd admin
#### 给sudoers文件加写权限
chmod u+w /etc/sudoers
#### 修改sudoers文件
vim /etc/sudoers
在root ALL=(ALL) ALL 的下一行添加代码:admin ALL=(ALL) ALL
#### 将sudoers文件改回只读
chmod 440 /etc/sudoers
修改软件源
将 /etc/apt/sources.list 中的地址全部替换成国内地址
参考 Ubuntu 如何更换软件源_疯魔coding君的博客-CSDN博客_ubuntu更换软件源
shang@shang-pc:~$ cd /etc/apt/
shang@shang-pc:/etc/apt$ cat sources.list
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy main restricted
# deb-src https://mirros.tuna.tsinghua.edu.cn/ubuntu jammy main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates main restricted
# deb-src https://mirros.tuna.tsinghua.edu.cn/ubuntu jammy-updates main restricted
安装MySQL
shang@shang-pc:/etc$ apt-cache search mysql
mysql-client - MySQL database client (metapackage depending on the latest version)
mysql-client-8.0 - MySQL database client binaries
mysql-client-core-8.0 - MySQL database core client binaries
mysql-common - MySQL database common files, e.g. /etc/mysql/my.cnf
mysql-server - MySQL database server (metapackage depending on the latest version)
mysql-server-8.0 - MySQL database server binaries and system database setup
mysql-server-core-8.0 - MySQL database server binaries
shang@shang-pc:/etc$ sudo apt-get install mysql-server-8.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
....
通过日志查看密码,发现root用户竟然是空密码
shang@shang-pc:/var/log/mysql$ grep password error.log
2022-09-24T01:41:30.221737Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
mysql8取消了PASSWORD()函数
故应使用如下方式修改root密码:
UPDATE user SET authentication_string="" WHERE user="root";
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges ### 刷新权限表,使密码生效
修改MySQL配置接受来自任意IP的连接
/etc/mysql/mysql.conf.d
bind-address = 0.0.0.0
重启MySQL服务 service mysql restart
使用sudo mysql 进入mysql
shang@shang-pc:~$ sudo mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 8.0.30-0ubuntu0.22.04.1 (Ubuntu)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Shang@2022';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
### 修密码
mysql> ALTER USER USER() IDENTIFIED BY '123456';
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.00 sec)
### 使root用户能接收来自任意IP的连接
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
4 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
参考 Ubuntu 安装 Mysql server_白月蓝山的博客-CSDN博客_ubuntu安装mysql-server
忘记MySQL密码
[mysqld]
port=13306
#bind-address=127.0.0.1
bind-address=0.0.0.0
basedir = /data/mysql
datadir = /data/mysql/data
### 在配置文件中加上这个,然后重启MySQL服务
skip-grant-tables
此时不用密码可以直接登录MySQL
mysql -uroot -P 13306
flush privileges;
alter user "root"@"%" identified by "123456";
flush privileges;
退出MySQL,重启MySQL服务后,即可用新密码登录MySQL
导出数据到文件 mysqldump -u root -p lawyer > backup20231112.sql
安装JDK
shang@shang-pc:~$ apt-cache search openjdk
openjdk-17-jdk - OpenJDK Development Kit (JDK)
openjdk-18-jdk - OpenJDK Development Kit (JDK)
openjdk-8-jdk - OpenJDK Development Kit (JDK)
openjdk-8-jdk-headless - OpenJDK Development Kit (JDK) (headless)
shang@shang-pc:~$ sudo apt-get install openjdk-8-jdk
完成后使用 java -version 查看版本
#### 配置环境变量
[root@iZuf66np9geqcisgpw1rz3Z java-1.8.0-openjdk]# vim /etc/profile
#### 在其中加入以下配置
# set java environment
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH PATH
#### 使配置立即生效
[root@iZuf66np9geqcisgpw1rz3Z java-1.8.0-openjdk]# source /etc/profile
安装Nginx
定时任务
shang@shang-pc:~$ cat vim /etc/crontab
cat: vim: No such file or directory
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
# You can also override PATH, but by default, newer versions inherit it from the environment
#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#凌晨2:01关机
01 2 * * * root /sbin/shutdown -h now
设置好之后,执行 sudo service cron restart 重启crontab服务
如果想开启syslog记录cron日志,需要编辑/etc/rsyslog.d/50-default.conf,去掉cron前的#
开机自动执行脚本
shang@shang-pc:/etc$ cat /etc/rc.local
#!/bin/sh
/home/shang/restart-neighbor-group-service.sh
exit 0
在/lib/systemd/system/rc-local.service中配置了服务,系统启动时将执行/etc/rc.local中的内容
需要注意,开机启动时,是以root用户来执行rc.local中的内容的
Ubuntu-server修改时间格式为24H格式
### 加上LC_TIME这行即可
shang@shang-pc:~$ cat /etc/default/locale
LANG=en_US.UTF-8
LC_TIME=en_DK.UTF-8
Logbak时间格式显示为24H格式
<!-- 在日志格式配置后添加“CTT”或“GMT+8” -->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS,GMT+8} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
SSH提示
Unable to negotiate with 192.168.17.207 port 22: no matching host key type found. Their offer: ssh-rsa
openssh觉得ssh-rsa加密方式不安全, 直接从8.8开始默认不允许这种密钥用于登陆了
加上如下参数即可
ssh -oHostKeyAlgorithms=+ssh-rsa root@192.168.17.207
SSH端口转发
将本机65002端口接收到的任意来源连接转发到172.16.34.179的80端口
ssh -L <本地ip>:<本地端口>:<目标ip>:<目标端口> 用户名@<ssh机器IP> -p <ssh机器端口>
root@iZuf65wxtpyt99pkmrsg2uZ:~# ssh -fCNL *:65002:localhost:80 root@172.16.34.179
root@iZuf65wxtpyt99pkmrsg2uZ:~# netstat -tunlp |grep 65002
tcp 0 0 0.0.0.0:65002 0.0.0.0:* LISTEN 1718952/ssh
tcp6 0 0 :::65002 :::* LISTEN 1718952/ssh
注意上面netstat结果中的65002前面为0.0.0.0表示接收任意来源的链接,如果前面为127.0.0.1则只接收来自本机的连接
-C 压缩传输,增加传输的效率
-f 将SSH传输放在后台执行
-N 建立静默连接,就是建立了连接(不执行登录shell)
-g 复用访问时作为网关,支持多主机访问本地侦听端口
-L 本地端口转发
-R 远程端口转发
-D 动态转发
-P 指定SSH的端口