linux-doc-常见问题和使用

问题

vim中文乱码

1
2
3
4
5
6
7
vim ~/.vimrc

set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1
set enc=utf8
set fencs=utf8,gbk,gb2312,gb18030

# 保存,重新vim打开文件即可

systemctl command not found

systemctl: command not found

可以使用service代替
service语法有一点区别

1
2
systemctl start mysqld
service mysqld start

centos8

设置代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 假设我们要设置代理为 IP:PORT

# 网页上网
# 网页上网设置代理很简单,在firefox浏览器下 Edit-->>Preferences-->>Advanced-->>Network
# 在Connection下点击Settings,里面的manual proxy configuration里设置IP和PORT即可

# yum代理设置
vim /etc/yum.conf
# 在里面添加这一行:proxy=IP:PORT
# 这里的IP 为你要设置的IP ,PORT 是你要设置的端口
# porxy=10.211.55.2:7890


# wget代理设置
vim /etc/wgetrc
# 添加下面两行:
http_proxy = IP:PORT
ftp_proxy = IP:PORT
#http_proxy = http://10.211.55.2:7890/
#https_proxy = http://10.211.55.2:7890/

# 系统环境代理设置
vim /etc/profile
# 如果只想给自己的账户设置,则编辑~/.bashrc即可
# 添加三行:
# add proxy for network
export http_proxy="http://child-prc.intel.com:913"
export https_proxy="http://child-prc.intel.com:913"
export ftp_proxy=$http_proxy
#然后source /etc/profile 或者source ~/.bashrc即可

查找大文件

1
2
# 从/目录开始查找大于800m的文件
find / -type f -size +800M

没有初始化root

1
2
# 设置密码就可以了
sudo passwd

Failed to download metadata for repo ‘AppStream’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 进入yum的repos目录
cd /etc/yum.repos.d/

# 修改所有的CentOS文件内容
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

# 更新yum源为阿里镜像
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
yum clean all
yum makecache

# yum安装测试是否可以yum安装
yum install wget –y

no match for argument

在使用yum安装工具的时候,产生这个错误的原因是未配置yum源,解决方法是就安装yum

  • 方法1
1
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
  • 方法2
1
sudo yum install epel-release

Another app is currently holding the yum lock

可能是系统自动升级正在运行,yum在锁定状态中。

1
rm -f /var/run/yum.pid

Ubuntu20.04

安装vim

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 安装vim
sudo apt-get install vim

# 安装完成后进入/etc/vim目录下配置文件
cd /etc/vim
sudo vim vimrc
# 内容
set number
set history=1000
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set showmatch
# 保存退出

使用root用户登录系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 在终端输入命令
sudo passwd root
# 根据提示输入密码
...

# 修改 50-ubuntu.conf 文件
sudo gedit /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf
# 文件末尾添加
greeter-show-manual-login=true #手工输入登陆系统的用户名和密码
allow-guest=false #不允许guest登录(可选)
# 保存

# 修改 gdm-autologin 文件
# 注释第3行
auth required pam_succeed_if.so user != root quiet_success
# 保存

# 修改 gdm-password 文件
sudo gedit /etc/pam.d/gdm-password
# 注释第3行
auth required pam_succeed_if.so user != root quiet_success
# 保存

# 修改 /root/.profile 文件
sudo gedit /root/.profile
# 注释末尾行
mesg n 2> /dev/null || true
# 添加新行
tty -s&&mesg n || true
# 保存

# 注销当前用户,登录root用户
reboot

开启ssh

1
2
3
4
5
6
7
8
9
# 安装
sudo apt update
sudo apt install openssh-server

# 验证
sudo systemctl status ssh

# 防火墙,正常不用
sudo ufw allow ssh

安装老网络工具

1
sudo apt-get install net-tools

apt代理

1
2
3
4
5
vim /etc/apt/apt.conf.d/proxy.conf

# 内容
Acquire::http::Proxy "http://10.211.55.2:7890";
#Acquire::https::Proxy "https://10.211.55.2:7890"; # 如果没有https代理,不要配

问题

E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 5447 (unattended-upgr)

1
#