Linux常用命令
pip 常用命令¶
- 查看
pip命令安装目录pip -V - 查看
pip命令执行程序位置command -V pip - 查看当前
pip版本
pip --version - 列出所有已安装的包
pip list - 安装最新版本的numpy库
pip install numpy pip卸载指定库
pip uninstall numpypip指定版本安装指定包
pip install numpy==1.26.1pip搜索指定包可安装的所有版本
pip install numpy==
也可以到 https://pypi.org/ 官网取搜索指定库,然后查看Release historypip指定源安装指定库,适用于当前源安装该库较慢,临时切换源使用
pip install numpy -i https://pypi.doubanio.com/simple/pip指定文件批量安装库,在requirements.txt文件中定义需要安装的库
pip install -r requirements.txt- 指定文件批量卸载库
pip uninstall -r requirements.txt - 通过 pip 下载指定包到指定目录,但不安装它
pip download numpy -d /gm-data/ pip指定已下载或者已克隆的包进行安装
pip install ./gm-data/numpy-1.26.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whlpip查看指定包的兼容性
pip check numpypip查看已安装库的详细信息
pip show numpy- 查询当前可升级的
pip库
pip list --outdated pip升级指定安装包
pip install --upgrade numpypip升级pip自身
pip install --upgrade pippip查看当前源配置
pip config list- 永久性修改
pip源
pip config set global.index-url --site https://pypi.tuna.tsinghua.edu.cn/simple - 查看
pip下载的安装包的默认路径
python3 -m site
conda 常用命令¶
- 查看
conda版本
conda --version - 查看 conda 信息
conda info - 更新 conda 自身到最新版本,同时也会更新其它包
conda update conda - conda 更新指定包,这里更新通过
conda安装的zlib包
conda update zlib - 列出所有虚拟环境
conda env list
conda info -e - 创建一个
python版本为3.8.10的虚拟环境
conda create -n gpumall python==3.8.10 - 切换到名称为 gpumall 的虚拟环境
conda activate gpumall - 退出当前虚拟环境
conda deactivate - 删除指定虚拟环境
conda remove --name gpumall --all - 查看已安装的包
conda list - 指定目录创建虚拟环境
conda create -p /gm-data/myenv python=3.8.10 - 安装 numpy 指定包到当前虚拟环境
conda install numpy - 在指定虚拟环境中安装包,这里在
gpumall虚拟环境中安装nmupy包
conda install --name gpumall numpy - 删除或者卸载当前虚拟环境中的指定包
conda remove numpy - 删除或者卸载指定虚拟环境中安装包,这里在
gpumall虚拟环境中删除nmupy包
conda remove --name gpumall numpy - 搜索 numpy 包的所有版本
conda search numpy - 搜索大于或等于 1.24 版本以上的
numpy包
conda search 'numpy>=1.24' - 通过
conda安装包后,conda会在/root/.cache/conda目录下生成缓存,可以通过如下命令查看该目录缓存
du -sh /root/.cache/conda/ - 如果
/root/.cache/conda目录缓存较大,则可以通过如下命令清理conda缓存
conda clean --all - 从
gpumall虚拟环境来克隆一个名称为gm的新虚拟环境
conda create --name gm --clone gpumall - 导出虚拟环境中所安装的所有包到指定文件
conda env export --name gm > gm.yml - 删除指定虚拟环境
conda env remove --name gm
实例中压缩及解压命令¶
- 在实例中的压缩及解压缩命令常用到的有如下:
tar、zip、unzip、gzip、gunzip、7z、bzip2、bunzip2、xz、unxz、rar、unrar等。 tar命令进行压缩及解压 将file_or_directory文件或目录压缩为archive.tar
tar -cvf archive.tar file_or_directory
将多个文件或目录压缩到同一个文件中,这里将file1file2directory1directory2一起压缩为archive.tar文件
tar -cvf archive.tar file1 file2 directory1 directory2解压缩archive.tar文件到当前目录tar -xvf archive.tar解压缩archive.tar到/gm-data/目录下tar -xvf archive.tar -C /gm-data/-
zip 及 unzip 命令进行压缩和解压(
zip和unzip算是一对命令,zip 命令用来压缩,unzip 用来解压 zip 命令的压缩。) 将 file_or_directory 文件或目录压缩为 archive.zip
zip -r archive.zip file_or_directory
将多个文件或目录压缩到同一个文件中,这里将 file1 file2 directory1 directory2 一起压缩为 archive.zip 文件
zip -r archive.zip file1 file2 directory1 directory2解压缩 archive.zip 文件到当前目录
unzip archive.zip解压缩 archive.zip 到 /gm-data/ 目录下
unzip archive.zip -d /gm-data/ -
gzip及gunzip命令进行压缩和解压(gzip和gunzip也算是一对命令,gzip命令用来压缩,gunzip用来解压gzip命令的压缩。)
压缩文件名为file的文件
gzip file解压通过gzip压缩的文件
gunzip file.gz 7z命令进行压缩及解压缩 将file_or_directory文件或目录压缩为archive.7z
7z a archive.7z file_or_directory
将多个文件或目录压缩到同一个文件中,这里将file1file2directory1directory2一起压缩为archive.7z文件
7z a archive.7z file1 file2 directory1 directory2
解压缩archive.7z文件到当前目录
7z x archive.7z
解压缩archive.7z到/gm-data/目录下,注意-o/gm-data/之间没有空格
7z x archive.7z -o/gm-data/- bzip2 及 bunzip2 命令进行压缩和解压(
bzip2和bunzip2也算是一对命令,bzip2命令用来压缩,bunzip2用来解压bzip2命令的压缩。)
压缩文件名为file的文件
bzip2 file
解压通过gzip压缩的文件
bunzip2 file.bz2 xz及unxz命令进行压缩和解压(xz和unzx也算是一对命令,xz命令用来压缩,unxz用来解压xz命令的压缩。)
压缩文件名为file的文件
xz file
解压通过gzip压缩的文件
unxz file.bz2rar及unrar命令进行压缩和解压 将file_or_directory文件或目录压缩为archive.rarrar a archive.rar file_or_directory
将多个文件或目录压缩到同一个文件中,这里将file1file2directory1directory2一起压缩为archive.rar文件
rar a archive.rar file1 file2 directory1 directory2
解压缩archive.rar文件到当前目录
unrar x archive.rar
解压缩archive.rar到/gm-data/目录下
unrar x archive.rar /gm-data/
apt 安装及卸载软件包命令¶
更新本地软件包列表,更新镜像源
sudo apt-get update -y
安装指定软件包,前提是需要知道包名
sudo apt-get install busybox -y
卸载软件包但需要保留配置文件
sudo apt-get remove busybox -y
卸载软件包并删除配置文件
sudo apt-get purge busybox
更新所有软件包
apt-get upgrade
搜索软件包
apt-cache search busybox
Linux 基础命令¶
ls 命令相关用法
列出当前目录中的文件和目录:
ls
列出包括隐藏文件在内的所有文件:
ls -a
以长格式列出文件(显示权限、所有者、大小和修改日期):
ls -l
递归列出所有子目录:
ls -R
cd命令用法
进入指定目录:
cd /gm-data/
返回上一级目录:
cd ..
返回用户主目录:
cd- pwd命令用法
显示当前目录的完整路径:
pwd - mkdir命令用法
创建新目录
kdir new_directory
一次创建多个目录
mkdir dir1 dir2 dir3
递归创建目录
mkdir -p /path/to/dir1/dir2 - touch命令用法
创建一个新的空文件:
touch newfile.txt更新现有文件的时间戳:
touch existingfile.txt - cp命令用法
复制文件到新位置:
cp source.txt destination.txt
复制目录及其内容(递归复制):
cp -r source_directory destination_directory
mv命令用法
移动文件
mv source.txt /path/to/destination
重命名文件
mv oldname.txt newname.txt - 进程管理命令
显示所有运行中的进程
ps -ef
ps aux
显示特定用户的进程
ps -u root
查找当前实例中的 所有python 进程
ps -ef | grep python
ps aux | grep python
实时显示系统中的进程信息
top
杀掉特定PID的进程
kill PID
强制杀掉指定进程
kill -9 PID
根据进程名终止进程:
pkill process_name
终止所有名为给定名称的进程:
killall process_name
列出打开的文件
lsof
显示特定用户打开的文件:
lsof -u username
显示使用特定端口的进程:
lsof -i :port_number
运行一个命令,使其在退出终端后继续运行:
nohup command &
显示当前会话的所有作业:
jobs
将作业带回前台继续运行:
fg %job_number
将停止的作业在后台继续运行:
bg %job_number
GPU 相关命令¶
显示所有NVIDIA GPU的当前状态,包括利用率、温度、功率使用等:
nvidia-smi
每隔1秒刷新并显示所有GPU的状态:
nvidia-smi -l 1 或者
watch -n 1 nvidia-smi
显示特定GPU(例如GPU 0)的详细信息:
nvidia-smi -i 0
仅显示特定的信息,例如温度、利用率等:
nvidia-smi --query-gpu=temperature.gpu,utilization.gpu --format=csv
查看GPU上运行的进程:
py3smi
nvitop
仅获取GPU显存使用情况
nvidia-smi --query-gpu=memory.used,memory.total --format=csv
获取GPU的硬件和驱动版本信息:
nvidia-smi -a
显示特定GPU的GPU核心利用率和显存利用率:
nvidia-smi --query-gpu=utilization.gpu,utilization.memory --format=csv