Linux
Ubuntu 20.04 系统安装流程
-
NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
$ sudo add-apt-repository ppa:graphics-drivers/ppa $ ubuntu-drivers devices $ sudo apt install nvidia-driver-460 # edit GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub. 可以不用 GRUB_CMDLINE_LINUX_DEFAULT="quiet splash pci=realloc" or GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" $ sudo update-grub $ sudo reboot -
移动文件夹下所有文件, 包括子文件夹下的内容
Open a terminal and execute this command:
mv -v ~/Downloads/* ~/Videos/It will move all the files and folders from Downloads folder to Videos folder.
To move all files, but not folders:
If you are interested in moving all files (but not folders) from Downloads folder to Videos folder, use this command
find ~/Downloads/ -type f -print0 | xargs -0 mv -t ~/VideosTo move only files from the Download folders, but not from sub-folders:
If you want to move all files from the Downloads folder, but not any files within folders in the Download folder, use this command:
find ~/Downloads/ -maxdepth 1 -type f -print0 | xargs -0 mv -t ~/Videoshere,
-maxdepthoption specifies how deep find should try,1means, only the directory specified in the find command. You can try using2,3also to test. -
文件大小查看命令
查看某一个文件夹的大小 du -sh [文件夹] 查看当前文件夹下的文件大小总和 ls | wc -l -
文件查找命令
查找遍历文件夹下所有文件后缀为jpg的文件并复制 find [查找文件夹] -name "*.jpg" | xargs -i cp {} [输出文件夹] -
批量执行命令 awk
-
查找文件后批量处理
ls | grep zip | awk -F . '{system("echo " $1)}' "ffmpeg -i " $1 ".wav -ar 36000 ../Wave_2/" $1 ".wav" for %a in ("*.wav") do ffmpeg -i "%a" -ar 36000 "\%~na.wav" -
script 输入参数: 直接写 $1 就是第一个参数
-
获得当前文件夹名
echo $(basename $(pwd))
-
-
DNS服务器地址修改
找到/etc/resolv.conf
nameserver 就是DNS服务器地址
-
图形界面添加自动启动项
gnome-session-properties -
文本界面设置子启动服务
-
写服务文件,如nginx.service、redis.service、supervisord.service
[Unit]:服务的说明 Description:描述服务 After:描述服务类别 [Service]服务运行参数的设置 Type=forking 是后台运行的形式 ExecStart 为服务的具体运行命令 ExecReload 为服务的重启命令 ExecStop 为服务的停止命令 PrivateTmp=True 表示给服务分配独立的临时空间 注意:启动、重启、停止命令全部要求使用绝对路径 [Install] 服务安装的相关设置,可设置为多用户 WantedBy=multi-user.target -
文件保存在目录下:以754的权限。目录路径:/usr/lib/systemd/system/
设置开机自启动 [root@localhost ~]# systemctl enable nginx.service [root@localhost ~]# systemctl enable supervisord 停止开机自启动 [root@localhost ~]# systemctl disable nginx.service [root@localhost ~]# systemctl disable supervisord 验证一下是否为开机启动 [root@localhost ~]# systemctl is-enabled nginx [root@localhost ~]# systemctl is-enabled supervisord
-
-
开机自动启动脚本
写脚本放入/etc/profile.d/
-
Ubuntu引导损坏 引导修复
-
linux 使用rar
https://www.rarlab.com/download.htm找到对应linux的压缩包
wget https://www.rarlab.com/rar/rarlinux-x64-6.0.2.tar.gz tar -xvf rarlinux-x64-6.0.2.tar.gz cd rar sudo make # 解压 unrar x xxx.rar # 压缩 -
ubuntu tar 多线程压缩
-
安装pigz
apt-get install -y pigz -
压缩文件夹(默认占用所有cpu核心, 占用率50%-80%)
tar --use-compress-program=pigz -h -cvpf [tar file name] [dir] -
解压文件夹
tar --use-compress-program=pigz -xvpf [tar file name] -C [dir] -
需要限制cpu占用的话
taskset -c [core number start]-[core number end] [command] -
向压缩包里追加文件
tar -rvf [tar file name] [file you need to add]
-
-
格式化新的磁盘
Installing A New Hard Drive
- Start parted as follows:
sudo parted /dev/sdb- Create a new GPT disklabel (aka partition table):
(parted) mklabel gpt- Set the default unit to TB:
(parted) unit TB- Create one partition occupying all the space on the drive. For a 4TB drive:
(parted) mkpart Partition name? []? primary File system type? [ext2]? ext4 Start? 0 End? 4- Check that the results are correct:
(parted) printThere should be one partition occupying the entire drive.
- Save and quit “parted”:
(parted) quitCommand Line Formatting
To format the new partition as ext4 file system (best for use under Ubuntu):
sudo mkfs -t ext4 /dev/sdb1
To format the new partition as fat32 file system (best for use under Ubuntu & Windows):
sudo mkfs -t fat32 /dev/sdb1
As always, substitute “/dev/sdb1” with your own partition’s path.
-
匹配k380键盘
可能成功
-
开发常用组件安装,遇到gcc之类的基础组件缺失时使用
apt-get install build-essential -
向日葵 远程登录失败问题
需要轻量化桌面
sudo apt install lightdm -
查看某个文件夹下文件或文件夹的数量(递归)
# 查看文件数量 ls -lR | grep "^-" | wc -l # 查看文件夹数量 ls -lR | grep "^d" | wc -l -
非root用户cuda安装
-
磁盘空间清理
rm -rf ~/.cache/pip conda clean -a -
htop设置
- 使用htop命令查看进程的时候可以关闭重复线程方便查看
F2 (Setup) -Display options --Hide userland threads F10 (Done) -
Ubuntu 隐藏上方状态栏、左边任务栏及菜单按钮移到下方居中及隐藏(详细)
Ubuntu 隐藏上方状态栏、左边任务栏及菜单按钮移到下方居中及隐藏(详细)_锵锵锵锵~蒋的博客-CSDN博客_ubuntu隐藏任务栏
-
ubuntu 20.04 vps 开机自启动
cd /etc/profile.d/ vim xxx.sh chmod a+x xxx.sh -
zip相关指令
1.1. 查看压缩包内容和统计
zip -sf images.zip | grep -v *.jpg | wc -l- zip -sf: 查看zip压缩包内容
- grep -v: 去除不需要的行, 筛选需要的文件名
- wc -l: 按行统计
1.2. 解压压缩包内部分文件
zip -sf images.zip | head -n 10 # 查看压缩包前10行内容 unzip images.zip "images/00001/000003.jpg" -d . # 解压单个文件到当前文件夹1.3. 批量压缩文件夹并删除原文件夹
find . -maxdepth 1 -type d ! -name "." -exec sh -c 'zip -r -6 "{}.zip" "{}" && rm -r "{}"' \;
Docker 问题整理
Docker 开发环境配置 1 (1)
-
常用命令
docker pull ubuntu # get newest ubuntu image docker image ls # check all docker images docker ps -a # show all docker containers docker run -i -t -d [Image ID] bash # create a docker container in the background docker run --runtime=nvidia --name tts --gpus all -it -p 10022:22 [Image ID] docker exec -i -t [Container ID] bash # enter the container docker stop [Container ID] # stop the container docker start [Container ID] # start the container docker build -f Dockerfile . # docker 使用Dockerfile建立镜像 docker network inspect bridge -f '{{json .Containers}}' # host下查看docker的ip地址 -
换源
# 打开配置文件 sudo vim /etc/docker/daemon.json # 添加阿里源 { "registry-mirrors": ["https://md4nbj2f.mirror.aliyuncs.com"] } #重载配置文件 sudo systemctl daemon-reload # 重启docker sudo systemctl restart docker -
docker中安装使用openvpn
需要注意的是docker容器需要有host的权限!
docker run --privileged xxxxxxxx -
docker显卡插件
$curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - $curl -s -L https://nvidia.github.io/nvidia-docker/ubuntu18.04/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list $sudo apt-get update $sudo apt-get install nvidia-docker2 $sudo pkill -SIGHUP dockerd $docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi -
删除docker none镜像
有效的 none 镜像Docker文件系统的组成,docker镜像是由很多 layers组成的,每个 layer之间有父子关系,所有的docker文件系统层默认都存储在/var/lib/docker/graph目录下,docker称之为图层数据库。
最后做一个总结< none>:< none> 镜像是一种中间镜像,我们可以使用docker images -a来看到,他们不会造成硬盘空间占用的问题(因为这是镜像的父层,必须存在的),但是会给我们的判断带来迷惑。
无效的 none 镜像
另一种类型的 < none>:< none> 镜像是dangling images ,这种类型会造成磁盘空间占用问题。
像Java和Golang这种编程语言都有一个内存区,这个内存区不会关联任何的代码。这些语言的垃圾回收系统优先回收这块区域的空间,将他返回给堆内存,所以这块内存区对于之后的内存分配是有用的
docker的悬挂(dangling)文件系统与上面的原理类似,他是没有被使用到的并且不会关联任何镜像,因此我们需要一种机制去清理这些悬空镜像。
我们在上文已经提到了有效的< none>镜像,他们是一种中间层,那无效的< none>镜像又是怎么出现的?这些 dangling镜像主要是我们触发 docker build 和 docker pull命令产生的。
使用下面的命令可以清理
sudo docker rmi $(sudo docker images -f “dangling=true” -q)
docker没有自动垃圾回收处理机制,未来可能会有这方面的改进,但是目前我们只能这样手动清理(写个脚本就好)。
Docker Dockerfile
-
换源
RUN sed -i s/deb.debian.org/mirrors.aliyun.com/g /etc/apt/sources.list RUN apt-get clean RUN pip install -U pip RUN pip config set global.index-url http://mirrors.aliyun.com/pypi/simple RUN pip config set install.trusted-host mirrors.aliyun.com- 或者直接用-i命令接在install后面
pip install xxx -i https://pypi.douban.com/simple/ -
当dockerfile安装失败的时候, 想进入容器debug
如果在构建Docker镜像时遇到失败,你可以使用**
--no-cache**选项强制重新构建,以便解决某些缓存相关的问题。此外,你还可以将失败的构建层作为一个新的容器运行,以便进入容器并手动调试问题。要进入失败的Docker构建,首先找到最后一个构建层的ID。在构建过程中,你会看到类似以下内容的输出:
sqlCopy code Step 3/6 : RUN apt-get update && apt-get install -y software-properties-common && add-apt-repository ppa:deadsnakes/ppa && apt-get update && apt-get install -y python3.6 python3.6-dev python3.6-venv python3-pip ---> Running in 54f176c9b38d在这里,**
54f176c9b38d**是构建层的ID。构建失败后,使用以下命令创建一个新的容器并运行:arduinoCopy code docker run -it --rm 54f176c9b38d bash现在你应该已经进入了容器。你可以手动运行命令来尝试找出导致构建失败的原因。在解决问题后,使用**
exit**命令离开容器,并尝试重新构建Docker镜像。
Docker使用ubuntu初始配置
- 更新apt-get
apt-get update
-
更换apt-get源
-
安装cmake
How to Install CMake on Ubuntu 20.04 LTS
-
挂载宿主机硬盘
# 使用-v 挂载多个文件夹 docker run --runtime=nvidia --name sqf_mvg -v "/algorithm/:/algorithm/" -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY --gpus all -it --net host sqf_workspace:lastest /bin/bash docker run -it -v "[host dir]:/[docker target dir]" [image id] /bin/bashhttps://blog.csdn.net/qq_41830712/article/details/90721395 --net 设置网络模式 bridge 模式,使用–net=bridge指定,默认设置。 none 模式,使用–net=none指定。 host 模式,使用–net=host指定。 container 模式,使用–net=container:容器名称或ID指定 -
对修改的container进行保存
docker commit -m="[new image name]" 7cd5094bf22f [container name]:lastest -
docker 导入导出容器
1. 查看容器id docker container ls -a 2. 导出容器 docker export [container id] > xxx.tar 3. 在其他机器导入容器 docker import - [repository name] < xxx.tar-
docker import之后docker run报错
**docker: Error response from daemon: No command specified.**-
解决方法:
在docker run命令最后加上command, 一般是/bin/bash
-
-
docker error
- 一些服务器在安装用到nvidia服务的Dockerfile的时候可能会报错
Error response from daemon: could not select device driver "" with capabilities: [[gpu]]
- 原因: host没有安装nvidia适配docker的驱动
# 给apt加上nvidia的安装包的目录
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
# 更新apt, 安装驱动, 重启dokcer服务
sudo apt-get update
sudo apt-get install nvidia-container-runtime
sudo service docker restart
apt-get update
- 有时候docker使用apt-get update的时候可能会有下面的报错
Reading package lists... Done
W: GPG error: https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64 InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY A4B469963BF863CC
E: The repository 'https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
# 解决
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC
# 如果上面一条报错
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-key A4B469963BF863CC && gpg --export --armor A4B469963BF863CC | apt-key add -
- 遇到库缺失问题,安装apt-file查找库
apt-get install apt-file
apt-file search liblapack
apt-file search libblas
libatlas-base-dev: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so
libatlas3-base: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3
libatlas3-base: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3
liblapack-dev: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so
liblapack3: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3
liblapack3: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
libopenblas-base: /usr/lib/x86_64-linux-gnu/openblas/liblapack.so.3
libopenblas-dev: /usr/lib/x86_64-linux-gnu/openblas/liblapack.so
revolution-mkl: /usr/lib/R/lib/liblapack.so
revolution-mkl: /usr/lib/R/lib/liblapack.so.3gf
###############
libatlas3-base: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3
libatlas3-base: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
libblas3: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3
libblas3: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
libopenblas-base: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
revolution-mkl: /usr/lib/R/lib/libblas.so.3gf
Proxy和换源
-
wget 使用代理
- For all users of the system via the
/etc/wgetrcor for the user only with the~/.wgetrcfile:
use_proxy=yes http_proxy=127.0.0.1:8080 https_proxy=127.0.0.1:8080 - For all users of the system via the
-
apt-get 换源
清华源生成源的路径点下面的链接, 修改**/etc/apt/sources.list**
ubuntu | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
sudo apt-get update # 更新源 -
alpine修改镜像源
-
使用阿里镜像 https://mirrors.aliyun.com
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories -
使用科大镜像 http://mirrors.ustc.edu.cn
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
-
-
anaconda 安装后替换源
-
pip 换源
-
cmake 使用代理
-
需要在CMakeLists.txt文件中添加代理地址
set(ENV{http_proxy} "http://[url]:[port]") set(ENV{https_proxy} "https://[url]:[port]")
-