Written with StackEdit.

Common

查询一个文件夹及其子文件夹下的所有文件中是否包含某个字符串

1
Get-ChildItem -Path "." -Recurse | Select-String -Pattern ""

查询当前目录中的文件总数

1
(Get-Childitem -Path . -File | Measure-Object).Count

端口查询 PID

1
netstat -ano | findstr "<port_ID>"

PID 查询进程

1
tasklist | findstr "<PID>"

开启 / 关闭 ipv6 临时地址 ( 需重启网卡 )[1]

1
netsh interface ipv6 set privacy state=[disable | enable]

打印 CPU 占用最高的 10 进程 ( ? )

1
Get-Process | Sort-Object -Property CPU -Descending | Select -First 10 | Format-Table -Property ID, Name, CPU

更改一个文件夹及其子文件夹下所有文件的最后修改时间

1
Get-ChildItem -Path . -Recurse | ForEach-Object { $_.LastWriteTime = Get-Date }

打印文件结构

1
Tree . /f

打印当前文件夹下所有文件名,筛选后缀并打印行号

1
2
# /n 用于打印行号
Get-ChildItem -File | Select-Object -ExpandProperty Name | findStr /n 'str'

压缩 .zip[2]

1
Compress-Archive -Path ./dir -DestinationPath ./dir.zip
  • 压不了需分卷的特大文件

列出当前目录下所有子目录的大小

1
2
3
4
5
6
7
Get-ChildItem -Directory | ForEach-Object {
$dirSize = Get-ChildItem $_.FullName -Recurse | Measure-Object -Property Length -Sum
[PSCustomObject]@{
Directory = $_.FullName
Size = $dirSize.Sum / 1MB # 将字节转换为 MB
}
}

删除文件夹。本来是用于删除需要管理员权限的某个目录,执行该命令后能删除一般文件和文件夹,但仍然无法完全删空 .git,这部分还是要手动删除。

1
Remove-Item -Path C:\Example -Recurse

文件互传。在 Windows 下使用 scp 需有 OpenSSH。WIn10-Arm64 WSL1 日常找不到命令,需在命令行执行。

1
2
# 远程拉到本地
scp -r remote_user@remote_ip:file_source file_target
  • 参数
    • -P: 配置为 SSH 端口
  • e.g.
    • scp -r admin@192.168.1.3:D:\Docs C:\Users\user\Documents\Docs
      
      1
      2
      3
      4

      ## WSL

      列出所有内核

wsl --list --verbose
wsl -l -v

1
2

关闭子系统

wsl --terminate Ubuntu-22.04

1
2

关闭 WSL

wsl --shutdown

1
2
3
4
5
6

## SSH

跳板连接
```bash
ssh uname@target_ip -p 22 -J uname@proxy_ip:22

Git

回滚当前分支下所有未暂存的修改

1
git checkout .

对比 diff

1
git diff origin/<branch> [file]

clone 指定分支

1
git clone -b <branch> <repo>

获取指定 commit 的仓库

1
2
# clone 当前仓库后
git checkout <commit_hash>

git 能够识别文件移动和重命名,但应该有一些条件。

1
2
rename docs/articles/LeetCode/{Vol.1.md => Vol.01.md} (97%)
rename docs/journals/{ => 2024}/Apr.md (98%)

Pip

查看已安装的包版本

1
2
3
pip list | findstr <package>
--- or
pip show <package>

Screen

开一个终端

1
screen  # 我喜欢不带参数

Detach

1
Ctrl + A D

查看

1
screen -ls`

Attach

1
screen -r <ID>

Kill

1
screen -XS <ID> quit

Linux

查询数据包每一跳路径

1
tracert

安装 ifconfig 和 ping

1
apt-get update && apt-get install net-tools iputils-ping

kernel 版本

1
uname -a

release 版本

1
lsb_release -a

端口查询 PID ( netstat 需要安装 net-tools )

1
netstat -anp | grep "<port_ID>"

四大件

1
apt install net-tools lsb-release iputils-ping  # cname 自带

控制台输出同时重定向到文件

1
${CMD} 2>&1 | tee ${CMD}_output.log

查询用户

1
whoami

find

  • 查询一个文件夹及其子文件夹下的所有文件名中是否包含某个字符串
    1
    find /path/to/directory -type f | grep "str"
  • 在项目目录下查找所有可执行文件
    1
    find . -type f -executable

grep

  • -I: 不查找二进制文件

apt

查看已安装包

1
dpkg -l

从 deb pkg 安装

1
dpkg -i ${PKG}.deb

Query available versions

1
policy

Identify if the packages are available

1
search

Verify if the packages are installed

1
list --installed <library>

查询安装指定版本的软件

卸载软件包 ( 保留依赖 )

1
remove

权限

文件创建时权限

1
umask

打印权限 ( e.g. 755 )

1
stat -c "%a" /path

权限修改

1
# chmod / setfacl

环境变量

  • $USER

psql

PostgreSQL 交互。

默认用户 postgres

1
psql -U postgres [-d <db_name>]

列出所有数据库表

1
\l

查看用户

1
SELECT rolnames FROM pg_roles;

创建用户

1
CREATE USER <username> WITH PASSWORD '<password>';

创建数据库

1
CREATE DATABASE <database>;

退出

1
\q

Numpy

布尔矩阵 ( 遵循布尔运算 )[3]

1
np.array(A, dtype=bool)

常用

  • 数乘与 np.dot
  • 矩阵比较: A == B(A == B).all()
  • EE: np.eye()
  • 最大值 / 最大值索引: np.max()np.argmax()
  • 欧式距离: np.linalg.norm()

  1. window关闭临时ipv6地址、开启临时ipv6地址-CSDN博客 ↩︎

  2. Compress-Archive (Microsoft.PowerShell.Archive) - PowerShell | Microsoft Learn ↩︎

  3. 2101. 引爆最多的炸弹 - 力扣(LeetCode) ↩︎