This is a simple Ubuntu command cheatsheet for myself.
GPU
- Use NVIDIA System Management Interface (
nvidia-smi):
$ nvidia-smi
Thu Jun 22 11:28:07 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.116.04 Driver Version: 525.116.04 CUDA Version: 12.0 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... On | 00000000:67:00.0 Off | Off |
| 0% 48C P8 29W / 450W | 3997MiB / 24564MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 43171 C python3 3994MiB |
+-----------------------------------------------------------------------------+- Check GPU usage using
nvtop: install the package usingsudo apt install nvtopand then runnvtop
File System
-
psmeans process status:-
-u: list all processes by user name: -
-e: view all the running processes -
-f: view full-format listingps -u hjwang PID TTY TIME CMD 3558 ? 00:00:02 sshd 3559 pts/0 00:00:00 bash ... 22112 ? 01:17:52 python
|: pipe a command that lets you use two or more commands such that output of one command serves as input to the next.grepis a command-line utility for searching plain-text data sets for lines that match a regular expression.ps -ef | grep pythoncan be use to show all running processes with python. -
-
kill PID: terminate a process using its ID:kill 22112(gracefully) orkill -9 22112(forcefully and immediately) -
du -sh *: list the sizes of all files and sub-folders. -
tree: print the directory tree in terminal: install usingsudo apt-get install tree
OS
- Show OS version:
lsb_release -a
Python
Change pip source:
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
Writing to /home/sedy/.config/pip/pip.confVPN
Get link from https://airtcp6.com/
mkdir clash
cd clash
wget https://github.com/Dreamacro/clash/releases/download/v1.18.0/clash-linux-amd64-v1.18.0.gz
gzip -d clash-linux-amd64-v1.18.0.gz
mv clash-linux-amd64-v1.18.0 clash
chmod +x clash
wget -O config.yaml https://airchats.xyz/link/xxlFHIZsFzxkBaBHlapx?clash=1
./clash -d .SFTP
https://linuxhint.com/setup-sftp-server-ubuntu/
sudo apt install ssh
sudo vim /etc/ssh/sshd_configadd the following to the end of the file:
Match group sftp
ChrootDirectory /home
X11Forwarding no
AllowTcpForwarding noForceCommand internal-sftp will disable SSH, which should not be included.
restart, add group, add/modify user, change permission
sudo systemctl restart ssh
sudo addgroup sftp
sudo useradd -m new_user_john -g sftp
sudo passwd new_user_john
sudo usermod -a -G sftp existing_user_tom
sudo chmod 700 /home/new_user_john
sudo chmod 700 /home/existing_user_tom/Use FileZilla to connect.
PS. The featured image for this post is generated using Stable Diffusion, whose full parameters with model link can be found at Takin.AI.
Mac
add environment variables: `vim ~/.bash_profile``
add to file: `export OPENAI_API_KEY=sk-xxx``
View environment variables: printenv
Process
-
Control + Z to suspend a process - it is still running in the background
-
fgto continue the process -
jobsto see all suspended jobs[1] + suspended scrapy crawl ssrn [2] + suspended scrapy crawl ssrn -
kill %1to terminate a suspended job.%1is the index.
Git
Git Reset and Force Push
To revert to a previous commit and force the remote repository to sync with your local repository:
-
First, find the commit hash you want to revert to:
git log -
Reset to that commit (replace COMMIT_HASH with the actual hash):
git reset --hard COMMIT_HASH -
Force push to remote repository:
git push -f origin main⚠️ Warning: Force push rewrites the remote history. Only use it when you're sure and have communicated with your team.