Terminal Command

Python

  1. pipreqs . —encoding=utf8 —force —use-local生成当前目录下所需要的requirement.txt
  2. CUDA/mps
    1. Device: GPU / Host: CPU
    2. @cuda.jit: 函数 on GPU (import numba)
    3. cuda.synchronize() 同步, 等待GPU执行完 再执行CPU
    4. CUDA_VISIBLE_DEVICES=‘0’ 使用0卡运行核函数
    5. 调用
     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)
    
  3. Cython: .pyx (cdef; cpdef)
    1. 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

  4. 抛出异常

     try:
     except Exception as e:
     	print(e)
    

Terminal

  1. sudo 管理员命令
  2. sudo apt-get install (linux)
  3. chsh -s /bin/bash 将终端切换成 -bash
  4. chsh -s /bin/zsh 将终端切换成 -zsh
  5. arch -arm64/ - version/ -help 架构命令

查询

  1. ip address
  2. curl ip.gs 查看IP地址 ifconfig
  3. powermetrics (mac)
  4. watch -n 1 nvidia-smi 查看英伟达显卡
  5. du -h —max-depth 1 查看所有子目录和所占容量
  6. df -h 显示文件系统的磁盘空间使用情况
  7. sudo fdisk -l 查看所有装在机器上的可识别磁盘
  8. tree -A -d 打印目录结构
  9. ps -aux 查看进程
  10. ls 显示当前目录的内容
  11. cd 改变浏览位置(常用在ls之后)
  12. cat <filename> 显示或连接文件
  13. pwd 显示当前路径
  14. where/which 查询环境路径

编译运行(可后台)

  1. g++/gcc 编译C语言和C++
  2. javac 编译java
  3. java 运行java
  4. nohup <command> & 后台挂起
  5. tail -f nohup.out 查看进度
    1. 终止:
      1. ps -aux | grep file name 查看对应进程
      2. kill -9 进程ID (PID)

文件操作

  1. nano/vim打开文件修改
  2. touch 创建新文件
  3. mv
  4. cp
  5. sudo chown -R user:user /path/to/your/folder 将文件夹所有权从 root 转移到普通用户
  6. sudo mkfs -t ext4 /dev/sdb 格式化ssd
  7. sudo mount -t ext4 /dev/sdb '/home/david/4tb' 挂载硬盘到特定路径下
  8. rm (-rf)删除文件或目录 rm filename
  9. open 使用默认的程序打开文件 open filename
  10. chflags hidden 隐藏文件// command + shift + . 显示隐藏文件
  11. 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

  1. dock images 查看镜像
  2. docker ps -a 查看容器
  3. 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 通过镜像生成容器
  4. docker start/stop <容器名>容器名>
  5. 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

  1. git init 创建本地仓库(repository)
  2. git add 把文件添加到暂存区(index)
  3. git commit -m “”把文件从暂存区提交进入本地仓库(一次提交记录)
  4. git status 显示状态
  5. git log /git relog查看历史git log –all –pretty=oneline –abbrev-commit –graph
    1. —all 显示所有分支
    2. —pretty=oneline 将提交信息显示为一行
    3. —abbrev-commit 使得输出的commit更简短
    4. —graph 以图的形式输出
  6. git reset —hard commitID 版本回退
  7. vim 修改 egitsc->”:wq”保存退出
  8. git []branch [-a] 查看[远程]分支
  9. git branch [-d]+分支名 创建[删除]分支
  10. git checkout (-b) 分支名(/远端名 origin/beta) 创建并切换到指定分支(基于远端分支)
  11. git merge+分支名 将指定分支合并入当前分支
  12. git diff <branch1><branch2> 显示两个分支的不同

Remote

1.  git remote add [远端名称][SSH/HTTPS] 与远程库对接

  1. git remote 查看远程仓库

  2. git branch -vv 查看远程仓库和本地仓库的对应关系

  3. git push [-f][--set-upstream][远端名称][本地分支名][:远端分支名] 推送文件 [-f]:强制覆盖

  4. git clone [SSH/HTTPS] 克隆远端仓库到本地

  5. git fetch [remote name][branch name] 抓取远端的特定分支到本地 但不合并

  6. git pull [remote name][branch name] = fetch + merge

  7. git push [remote name] --delete [branchname]删除远程分支

Remote SSH key

  1. 配置密钥

     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>
    
  2. 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

  1. 配置
vim ~/.bash_profile / vim ~/.zsh_profile
export M2_HOME=maven
export PATH=$PATH:$M2_HOME/bin
source ~/.bash_profile / source ~/.zsh_profile
  1. mvn -v 显示出下列信息则代表Maven安装配置成功
  2. 设置settings.xml

Homebrew

  1. 安装软件:brew install 软件名,例:brew install nginx
  2. 搜索软件:brew search 软件名,例:brew search nginx
  3. 卸载软件:brew uninstall 软件名,例:brew uninstall nginx
  4. 更新所有软件:brew update
  5. 更新具体软件:brew upgrade 软件名 ,例:brew upgrade nginx
  6. 显示已安装软件:brew list
  7. 查看软件信息:brew info/home 软件名 ,例:brew info git / brew home git
  8. 显示包依赖:brew reps
  9. 显示安装的服务:brew services list
  10. 安装服务启动、停止、重启: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:

  • Computer Environment
  • NeRF
  • 3DGS
  • SDS
  • Pretrain Diffusion