Terminal Command
Python
-
pipreqs . —encoding=utf8 —force —use-local
生成当前目录下所需要的requirement.txt - CUDA/mps
- Device: GPU / Host: CPU
-
@cuda.jit
: 函数 on GPU (import numba) -
cuda.synchronize()
同步, 等待GPU执行完 再执行CPU -
CUDA_VISIBLE_DEVICES=‘0’
使用0卡运行核函数 - 调用
device = torch.device('mps' if torch.backends.mps.is_built() else 'cpu') # device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model = model.to(device) data = data.to(device)
-
Cython: .pyx (cdef; cpdef)
- setup.py
from distutils.core import setup from Cython.Build import cythonize setup(ext_modules=cythonize(["examples_cy.pyx"]))
b. python setup.py build_ext —inplace
-
抛出异常
try: except Exception as e: print(e)
Terminal
-
sudo
管理员命令 -
sudo apt-get install
(linux) -
chsh -s /bin/bash
将终端切换成 -bash -
chsh -s /bin/zsh
将终端切换成 -zsh -
arch -arm64/ - version/ -help
架构命令
查询
ip address
-
curl ip.gs
查看IP地址 ifconfig -
powermetrics
(mac) -
watch -n 1 nvidia-smi
查看英伟达显卡 -
du -h —max-depth 1
查看所有子目录和所占容量 -
df -h
显示文件系统的磁盘空间使用情况 -
sudo fdisk -l
查看所有装在机器上的可识别磁盘 -
tree -A -d
打印目录结构 -
ps -aux
查看进程 -
ls
显示当前目录的内容 -
cd
改变浏览位置(常用在ls之后) -
cat <filename>
显示或连接文件 -
pwd
显示当前路径 -
where/which
查询环境路径
编译运行(可后台)
-
g++/gcc
编译C语言和C++ -
javac
编译java -
java
运行java -
nohup <command> &
后台挂起 -
tail -f nohup.out
查看进度- 终止:
-
ps -aux | grep file name
查看对应进程 -
kill -9 进程ID
(PID)
-
- 终止:
文件操作
-
nano/vim
打开文件修改 -
touch
创建新文件 mv
cp
-
sudo chown -R user:user /path/to/your/folder
将文件夹所有权从 root 转移到普通用户 -
sudo mkfs -t ext4 /dev/sdb
格式化ssd -
sudo mount -t ext4 /dev/sdb '/home/david/4tb'
挂载硬盘到特定路径下 -
rm (-rf)
删除文件或目录 rm filename -
open
使用默认的程序打开文件 open filename -
chflags hidden
隐藏文件// command + shift + . 显示隐藏文件 -
ffmpeg -framerate 10 -start_number 197 -i image_path/%d.jpg -c:v libx264 -pix_fmt yuv420p output.mp4
通过图片集生成视频
Vim
插件
- neovim
- Astronvim
- Treesitter-cli
- Lazygit
编辑模式:
-
i
光标位置进入编辑 -
A
本行结尾进入编辑 -
o
新增一行进入编辑 -
esc
退出
浏览模式:
-
: + wq
保存退出 -
: + q!
退出不保存 -
: + 12
跳转到12行 -
/ + 关键字
搜索关键字 -
dd
删除行 -
d
删除 -
v+拖动光标
选中文字 -
y
复制 -
p
从vim剪贴板粘贴 -
+p
从系统剪贴板粘贴 -
u
撤回
Docker
-
dock images
查看镜像 -
docker ps -a
查看容器 -
docker run —runtime=nvidia -e NVIDIA_DEVICES=0,1,2,3,4,5,6,7 —shm-size 16G -p xxxxx:22 -it -d -v /workspace:/workspace —name project_david xxx/py3_torch1.8.2_cuda11.5:v1 /bin/bash
通过镜像生成容器 -
docker start/stop
<容器名>容器名> -
docker exec -it ocr_project_david /bin/bash
进入容器
MySQL
brew service mysql stop
brew services start mysql
mysql -u root -p # 登陆mysql
create database database_name;
show databases;
use database_name;
DROP DATABASE your_database_name;
show tables;
desc table_name;
Git
Local
-
git init
创建本地仓库(repository) -
git add
把文件添加到暂存区(index) -
git commit -m “”
把文件从暂存区提交进入本地仓库(一次提交记录) -
git status
显示状态 -
git log /git relog
查看历史git log –all –pretty=oneline –abbrev-commit –graph- —all 显示所有分支
- —pretty=oneline 将提交信息显示为一行
- —abbrev-commit 使得输出的commit更简短
- —graph 以图的形式输出
-
git reset —hard commitID
版本回退 - vim 修改 egitsc->”:wq”保存退出
-
git []branch [-a]
查看[远程]分支 -
git branch [-d]+分支名
创建[删除]分支 -
git checkout (-b) 分支名(/远端名 origin/beta)
创建并切换到指定分支(基于远端分支) -
git merge+分支名
将指定分支合并入当前分支 -
git diff <branch1><branch2>
显示两个分支的不同
Remote
1. git remote add [远端名称][SSH/HTTPS]
与远程库对接
-
git remote
查看远程仓库 -
git branch -vv
查看远程仓库和本地仓库的对应关系 -
git push [-f][--set-upstream][远端名称][本地分支名][:远端分支名]
推送文件 [-f]:强制覆盖 -
git clone [SSH/HTTPS]
克隆远端仓库到本地 -
git fetch [remote name][branch name]
抓取远端的特定分支到本地 但不合并 -
git pull [remote name][branch name]
= fetch + merge -
git push [remote name] --delete [branchname]
删除远程分支
Remote SSH key
-
配置密钥
cd /.ssh ssh-keygen -t ed25519 -C "<comment>” 或ssh-keygen -t rsa -b 2048 -C "<comment>" # 配置密钥 cat ~/.ssh/ <filename>.pub chmod 600 <filename> ssh-add ~/.ssh/<filename>
-
vi config (修改配置文件)
Host github.sfu.ca User git IdentityFile /Users/davidqian/.ssh/sfu_github
SFU
ssh -p 24 rqa4@gateway.csil.sfu.ca
#(wget "https://www.cs.sfu.ca/~ashriram/Courses/CS295/assets/distrib/csil-linux.py”)只需要初始化一次就好了
python3 csil-linux.py
ssh -p 24 [rqa4@asb9700u-g02.csil.sfu.ca](mailto:rqa4@asb9700u-g02.csil.sfu.ca)
scp -P24 filename [USERNAME@csil-cpu1.csil.sfu.ca](mailto:USERNAME@csil-cpu1.csil.sfu.ca)
scp -P24 USERNAME@csil-cpu1.csil.sfu.ca:filename
Maven
- 配置
vim ~/.bash_profile / vim ~/.zsh_profile
export M2_HOME=maven
export PATH=$PATH:$M2_HOME/bin
source ~/.bash_profile / source ~/.zsh_profile
-
mvn -v
显示出下列信息则代表Maven安装配置成功 - 设置settings.xml
Homebrew
- 安装软件:brew install 软件名,例:brew install nginx
- 搜索软件:brew search 软件名,例:brew search nginx
- 卸载软件:brew uninstall 软件名,例:brew uninstall nginx
- 更新所有软件:brew update
- 更新具体软件:brew upgrade 软件名 ,例:brew upgrade nginx
- 显示已安装软件:brew list
- 查看软件信息:brew info/home 软件名 ,例:brew info git / brew home git
- 显示包依赖:brew reps
- 显示安装的服务:brew services list
- 安装服务启动、停止、重启:brew services start/stop/restart serverName
Folder
/boot:# all booting related information.
/dev:# all hardware devices attached to machine
/bin:# command line; all your executable binaries
/etc:# contain all your system configuration files in it
/opt:# add-on application software packages
/usr/local:# use by the system administrator when installing software locally
/var:# contains files to which the system writes data during the course of its operation.
/tmp:# contains necessary files that are **temporarily** required by the system as well as other software and applications running on the machine.
/lib:# contains kernel modules and those shared library images (the C programming code library) needed to **boot the system and run the commands** in the root filesystem
Enjoy Reading This Article?
Here are some more articles you might like to read next: