有一些经常用的命令总是记不住,这里整理下吧

Debian安装nodejs
curl -sL https://deb.nodesource.com/setup_12.x |  bash -
apt-get install -y nodejs
安装npm
apt install npm
安装pm2
npm install pm2 -g
更新npm
npm install -g npm
vps常用命令
1.查看ssh登录失败次数
grep "Failed password for root" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -nr | more
2.git更新
git stash
git pull origin master

4.更改默认python版本
cd /usr/bin
ls -l | grep python
rm -rf python
ln -s /usr/bin/python3  /usr/bin/python
5.pm2开机自启
pm2 startup
pm2 save
6.apt被占用
ps aux | grep -i apt
rclone挂载,卸载命令
rclone mount beifen:/ /GD --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 &
rclone mount honus:/ /GD1 --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 &
fusermount -qzu /www/wwwroot/download.honus.top/GD
设置cmd代理
set http_proxy=http://127.0.0.1:7890
set https_proxy=http://127.0.0.1:7890
整理迁移网站需要的吧
ssh保持连接
vim /etc/ssh/sshd_config
ClientAliveInterval 120
ClientAliveCountMax 720
systemctl restart sshd
.user.ini权限问题
chattr -i /www/wwwroot/tv.honus.top/.user.ini

解压文件夹下所有zip文件

ls *.zip | xargs -n1 unzip -o -P infected

linux crontab任务

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

00 03    * * * ./etc/profile; /bin/sh /mnt/test1.sh

aws修改为密码登陆

#!/bin/bash
echo root:YourPassWord |sudo chpasswd root
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config;
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
sudo service sshd restart

1.paramiko模块

执行screen之类的命令应使用invoke_shell()
client=paramiko.SSHClient()
key=paramiko.AutoAddPolicy()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ip, port, username=username, password=password,timeout=30)
chan = client.invoke_shell()
chan.send('screen -S a -d -m btfs/bin/btfs daemon\n')
sleep(1)

记得加\n与sleep(1)

2.apt安装直接确认不输入y/yes

apt-get -y install screen
yes|sh test.sh (待测试)

3.cmd中执行powershell指令(只允许将表达式作为通道第一个元素)

原命令
get-content config | %{$_ -replace '5001','5002'} > config1
cmd命令,bat脚本
powershell -Command "& { get-content config | ForEach-Object {$_ -replace '5001','5002'} > config1;}"

4.powershell处理文件第n行范围

if ($_.ReadCount -ge 167 -and $_.ReadCount -le 170) 
{
        $_ -replace 'false','true'
} 
else 
{
        $_     
}   

5.vue nginx配置

location /api {
        rewrite ^/api/(.*) /$1 break;
        proxy_pass http://127.0.0.1:5000;
        proxy_redirect          off;
            proxy_set_header        Host $host;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_connect_timeout   600;
            proxy_send_timeout     600;
            proxy_read_timeout     600;
    }
    location / {
        root /www/wwwroot/sql.honus.top/;
        index  index.html index.htm;
        try_files $uri $uri/ @rewrites;    
    }
    location @rewrites {
         rewrite ^(.+)$ /index.html last;
    }

安装python3.7

apt -y install wget build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
curl -O https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
tar -xf Python-3.7.3.tar.xz
cd Python-3.7.3
./configure --enable-optimizations
#编译安装
make altinstall

rm -rf /usr/bin/python
rm -rf /usr/bin/pip
ln -s /usr/local/bin/python3.7 /usr/bin/python
ln -s /usr/local/bin/pip3.7 /usr/bin/pip

python 类中使用装饰器

from functools import wraps
class Test:
    def on_message(fun):
        @wraps(fun)
        def print_me(self):
            fun(self)
        return print_me

    @on_message
    def test(self):
        print('res')
b=Test()
b.test()
最后修改:2022 年 04 月 09 日
如果觉得我的文章对你有用,请随意赞赏