-
查看所有子文件大小并排序
du -hs * | sort -hr
-
配置所有服务器的互相免密登录的
Python
脚本
在Windows10上的Ubuntu里面执行以下python文件即可配置1-num个服务器及本机之间,所有机器的双向免密登录。
import os
num = 5
for i in range(1, num):
if i in [2, 3, 4]: continue
k = i if i != 1 else ''
command = 'scp -rp lab{}:.ssh/id_rsa.pub lab_{}.pub'.format(k, k)
print("Download {}".format(i))
os.system(command)
command = 'cat lab_{}.pub >> authorized_keys'.format(k)
os.system(command)
command = 'rm -rf lab_{}.pub'.format(k)
os.system(command)
print("add system")
command = 'cat /mnt/c/Users/yourname/.ssh/id_rsa.pub >> authorized_keys'.format(k) # windows的pub key,vscode远程登录会用到
os.system(command)
print("add wsl")
command = 'cat ~/.ssh/id_rsa.pub >> authorized_keys'.format(k) # WSL的pub key,日常ssh会用到
os.system(command)
for i in range(1, num):
if i in [2, 3, 4]: continue
k = i if i != 1 else ''
command = 'scp -r authorized_keys lab{}:.ssh/'.format(k)
os.system(command)
command = 'scp -r ~/.ssh/config lab{}:.ssh/'.format(k)
os.system(command)
command = 'rm -rf authorized_keys'.format(k)
os.system(command)
删除超大文件夹
- 这里超大文件夹是指一个文件夹下有大量的文件。某次我吃饭前把程序启动,结果不小心写了个死循环,回来一看文件夹下已经创了200多万个小文件,
rm -rf
简直龟速,无法忍受,需要一个能够快速删除的方法: - 查看超大文件夹下的文件数
当文件夹下文件数目过多时,ls | wc -l
计算数量也变得非常慢,使用find
命令会快很多:find . -name "*" | wc -l
- 快速删除超大文件夹:
cd yourdirectory
perl -e 'for(<*>){unlink}'
批量终止包含某个关键字的进程
以关键词nni
为例
kill $(ps aux | grep 'nni' | awk '{print $2}')
网友评论