Linux解决集锦

Linux解决集锦

Windows与Linux虚拟机互ping

1.打开VMware 顶部菜单:
虚拟机-》可移动设备-》网络适配器-》设置
Linux解决集锦
2.将网络连接一栏改为NAT模式,确定
(注意:桥接模式、桥接模式并复制物理网络连接状态、NAT模式这三者是有区别的,遇到网络问题先调一调这里,但我这里桥接模式,NAT模式在虚拟机中都是能够上外网的)
Linux解决集锦
3.稍等几秒钟,查看右上角网络连接图标,应该获取到了ip地址。
Linux解决集锦

4.打开windows网络连接,将VMware Network Adapter VMnet8 改为启用
Linux解决集锦
5.此时在cmd里ping,应该能够ping通了
Linux解决集锦
6.实在不行,试一下关闭防火墙?
(见本集锦)

ubuntu防火墙操作命令

1、查看端口开启状态

sudo ufw status

2、开启某个端口,比如我开启的是8381

sudo ufw allow 8381

3、开启防火墙

sudo ufw enable

4、关闭防火墙

sudo ufw disable

5、重启防火墙

sudo ufw reload

6、禁止外部某个端口比如80

sudo ufw delete allow 80

7、查看端口ip

netstat -ltn

ubuntu gnome 诡异桌面(无图标,智能找顶端栏)解决

就像这样
Linux解决集锦
解决:

sudo apt-get install gnome-tweak-tool

然后

gnome-tweak-tool

Linux解决集锦
选完之后就解决
Linux解决集锦

话说这个工具还挺好用的,里面有很多可以调整外观的选项,可以探索一下

ubuntu16.04和18.04换国内源

(有的系统是source.list,下面以sources.list为例)

cd /etc/apt
ls  
sudo chmod 777 sources.list

图形界面打开
Linux解决集锦
提示:最好先做个备份,到时候可以换回来使用正常国外源

备份好了就可以放心删了,把里面全删了换成这个:

如果是ubuntu16.04

阿里源:

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse 

清华源:

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse 

桌面终端执行命令:

sudo apt update

更新软件列表,换源完成。

如果是ubuntu18.04

阿里源:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse 

清华源:

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse 

163源:

deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse 

3.更新源

桌面终端执行命令:

sudo apt update

更新软件列表,换源完成。

E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) (出现apt锁解决)

在Ubuntu中,有时候运用sudo apt-get install 安装软件时,会出现以下的情况

E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

解决方法:

1.查找所有apt相关的进程,并用命令杀死
例子:

pibot@ubuntu:~$ ps afx|grep apt
pts/0    S+     0:00          \_ grep --color=auto apt
?        Ss     0:00 /bin/sh /usr/lib/apt/apt.systemd.daily install
?        S      0:00  \_ /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held install

pibot@ubuntu:~$ sudo kill -9 2873
pibot@ubuntu:~$ sudo kill -9 2869

2.移除对应目录下的锁文件,强制重新配置软件包,更新软件包源文件:

pibot@ubuntu:~$ sudo rm /var/lib/dpkg/lock

pibot@ubuntu:~$ sudo dpkg --configure -a

pibot@ubuntu:~$ sudo apt update

问题解决

Linux虚拟机下某些USB设备不正常

一句话,调
Linux解决集锦
三个都试一下(但虚拟机直通USB设备有风险,我的虚拟机试了三个摄像头,linux系统都能识别,但使用v4l2读取都打不开,黑屏,而且不报错,偶然一次使用vlc打开过,就是在改过USB兼容性后)

Linux系统改国内源和还原国外源脚本

(以树莓派系统buster为例,作其它使用简单修改就可)

这是设置国内源的脚本,建议在终端下,并获得root权限后使用(set.sh)

#这是设置国内源的脚本,建议在终端下,并获得root权限后使用(set.sh)
file_sources="/etc/apt/sources.list"
file_sources_bak="/etc/apt/sources.list.bak"
file_raspi="/etc/apt/sources.list.d/raspi.list"
file_raspi_bak="/etc/apt/sources.list.d/raspi.list.bak"

if [ -f ${file_sources_bak} ];then
    echo ERR!:bak file exist, Have you changed it before? No changes will be writed!
else
    echo start change it to local sources!
    sudo cp ${file_sources} ${file_sources_bak}
    sudo cp ${file_raspi} ${file_raspi_bak}
    sudo chmod 777 ${file_sources}
    sudo chmod 777 ${file_raspi}
    sudo echo "deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi" > ${file_sources}
    sudo echo "deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ buster main" > ${file_raspi}
    echo  Enjoy local sources!
fi

这是换回国外源的脚本,建议在终端下,并获得root权限后使用(back.sh)

#这是换回国外源的脚本,建议在终端下,并获得root权限后使用(back.sh)
file_sources="/etc/apt/sources.list"
file_sources_bak="/etc/apt/sources.list.bak"
file_raspi="/etc/apt/sources.list.d/raspi.list"
file_raspi_bak="/etc/apt/sources.list.d/raspi.list.bak"

if [ -f ${file_sources_bak} ];then
    echo start change it to orignal sources!
    sudo rm -f ${file_sources}
    sudo rm -f ${file_raspi}
    sudo mv ${file_sources_bak} ${file_sources}
    sudo mv ${file_raspi_bak} ${file_raspi}
    echo  back to orignal sources!
else
    echo ERR!:bak file does not exist, Have you not changed it before? No changes will be writed!
fi

Windows和Linux换行符互转

Windows 转Linux

在windows下使用txt写好linux shell脚本后再拷贝到linux下执行会出现这样的错误Linux解决集锦
因为在dos/window下按一次回车键实际上输入的是“回车(CR)”和“换行(LF)”,而Linux/unix下按一次回车键只输入“换行(LF)”,所以文件在每行都会多了一个CR,所以Linux下运行时就会报错找不到命令,所以,解决问题之道,就是把dos文件格式转换为unix格式。

方法1:使用dos2unix命令转换

第一步:安装dos2unix命令,如果已经安装,跳过该步骤
centos:

  yum install dos2unix

ubuntu:

  sudo apt-get install dos2unix

第二步:转换

dos2unix /usr/apache-tomcat/bin/restart.sh

方法2:使用notepad++

  在windows系统下使用notepad++编辑该sh文件,双击文件右下角编码区域选择"转换为UNIX格式"

方法3:什么都不用安装

sed -i 's/\r//' /home/pi/Desktop/shell.sh

Linux转Windows

方法1:使用unix2dos命令转换

第一步:安装dos2unix命令,如果已经安装,跳过该步骤
centos:

  yum install unix2dos

ubuntu:

  sudo apt-get install unix2dos

第二步:转换

unix2dos /usr/apache-tomcat/bin/restart.sh

Ubuntu 下vi按i无法进入插入模式

Ubuntu下的vi编辑器是不完整的,你要在你的机器联网的情况下重新安装Vim,:在命令行输入:

sudo apt-get install vim-full

或者

sudo apt-get install vim 

这样你的vim 就完整了,其实vim和vi是一样的

Linux解决集锦Linux解决集锦 whstudio123 发布了7 篇原创文章 · 获赞 5 · 访问量 3042 私信 关注
上一篇:Ubuntu 18.04 更换apt源


下一篇:[Fenics有限元安装] 虚拟机Linux下,在ubuntu20.04上通过anaconda安装FEniCS有限元框架指南(适合新手小白,超详细)