Linux下常用命令整理

这篇note记录linux下常用command

Linux系统相关

查看Linux Server系统版本

lsb_release -a

查看当前系统的所有进程:

top

查看系统时间

timedatectl status

设置系统时间,例如America/New_York

sudo timedatectl set-timezone America/New_York

文件相关

显示当前目录下文件大小:

ls -l

显示特定文件的大小:

ls -l | grep 'name'

查看某个目录下的文件总大小:

du -sh path/to/folder

更改文件名:

mv file file'

GPU相关命令

持续显示显卡状况:

watch -n 1 nvidia-smi

查看使用GPU的所有进程:

fuser -v /dev/nvidia*

杀掉GPU的某个进程(把PID替换为对应进程ID):

kill -9 PID

查看Nvidia driver版本

nvidia-smi

查看Nvidia toolkit版本

nvcc -V

在Linux Server上创建新用户

在/home/目录下为用户username创建一个用户目录:

sudo useradd -m -d /home/username username

设置新用户的初始密码:

sudo passwd username

设置-s选项允许指定新用户的登录shell,例如/bin/bash

sudo useradd -s /bin/bash username

sudo chsh -s /bin/bash username (如果用户已存在)

查看用户的user id和groups信息:

id username

查看用户的所有信息:

sudo cat /etc/passwd | grep username

查看某一用户所拥有的权限:

groups username

Git Rebase

Merge multiple commits into one

First, Run the following command to start an interactive rebase for the last 5 commits:

git rebase -i HEAD~5

Change pick to squash (or s) for the last 9 commits, keeping pick for the first commit:

pick 123abc Commit message 1
squash 456def Commit message 2
squash 789ghi Commit message 3
...

Save and close the editor. Another editor window will open, allowing you to edit the commit message for the squashed commit. Modify it as needed and save.

Last, force-push if you've already pushed these commits to a remote branch:

git push origin branch-name --force

... 持续更新中!