Linux常见问题及解决方案

2024/7/15·1 views

删除输入的错误

有时候在linux终端中执行某个命令时,往往会输错命令,想删除掉重敲可以按backspace键,但这样较慢,一种简便技巧是,按住esc键同时按backspace键会较快删除【esc+backspace】组合键。或者【ctrl+u】组合键

当然,直接回车更直接,但可能会产生一堆的错误提示。
##vim
v / ctrl + v 可视模式, 缩进,d,D,y dw d$

vim :行号,行号 d表示文件夹,rwx-1 表示拥有者,rwx-2表示用户所在组,rwx-3表示其他人,使用chmod修改权限 chmod ug+w,o-w file1.txt file2.txt 给file1.txt 和file2.txt 加上对用户和用户组的写权限,去掉其他人的写权限

  1. 清空文件 gg跳到行首dG清空

  2. ctrl-c 发送 SIGINT 信号给前台进程bai组中的所有进du程。常用于终止正在运zhi行的程序。
    ctrl-z 发送 SIGTSTP 信号给前台进程dao组中的所有进程,常用于挂起一个进程。用户可以使用fg/bg操作继续前台或后台的任务,fg命令重新启动前台被中断的任务,bg命令把被中断的任务放在后台执行.
    ctrl-d 不是发送信号,而是表示一个特殊的二进制值,表示 EOF。
    ctrl-\ 发送 SIGQUIT 信号给前台进程组中的所有进程,终止前台进程并生成 core 文件。

linux下如何输入EOF

复制代码
ctrl + d 

不同系统有不同组合键

免密登录

shell 复制代码
visudo # 编辑/etc/sudoers文件
%cheng ALL=(ALL) NOPASSWD:ALL

免密使用sudo执行命令

复制代码
visudo

添加

复制代码
username ALL=(ALL) NOPASSWD: /path/to/command

如果想要可以执行所有命令,将/path/to/command更改成ALL即可,同时还可以限制不能执行某些命令,例如

复制代码
username ALL=(ALL) NOPASSWD:ALL,!/bin/bash

则不能执行/bin/bash命令

3) 验证监听端口

复制代码
lsof -n -i4TCP:3478 | grep LISTEN
lsof -n -i4TCP:5349 | grep LISTEN

或直接查看所有UDP/TCP 端口

复制代码
netstat -nat | grep LISTEN

cp 命令直接覆盖不提示

有的系统会默认添加-i参数的cp作为cp的别名来使用

shell 复制代码
alias cp='cp -i'

我们可以使用

shell 复制代码
\cp <file1><file2>

进行复制,cp命令前加个右斜杠即可 \cp。
这个右斜杠表示使用原生命令,因此可以直接覆盖

同样rm命令也可以这样使用

shell 复制代码
rm -i # \rm

也可以修改 ~/.bashrc 文件移除别名

添加字体

宋体是一种中文字体,通常用于 Windows 操作系统。在 Linux 操作系统中,默认情况下不会安装宋体字体,但您可以通过以下步骤将宋体字体安装到 Linux 中:

首先,从 Windows 操作系统上复制 SimSun.ttf 文件。您可以在 Windows 的 C:\Windows\Fonts 目录下找到该文件。

将 SimSun.ttf 文件复制到 Linux 操作系统上。

在 Linux 中创建一个新的字体目录(如果不存在)。您可以使用以下命令创建一个名
为 fonts 的目录:

复制代码
sudo mkdir -p /usr/share/fonts/truetype/custom/

将 SimSun.ttf 文件移动到新创建的目录中。您可以使用以下命令完成此操作:

复制代码
sudo mv SimSun.ttf /usr/share/fonts/truetype/custom/

然后,重新生成字体缓存。

复制代码
cd /usr/share/fonts/truetype/custom/
mkfontscale
mkfontdir

您可以使用以下命令完成此操作:

复制代码
fc-cache -f -v

现在,您已将宋体字体安装到 Linux 操作系统中。在应用程序中选择字体时,您应该能够看到宋体字体可供选择。

安装Ubuntu后另外磁盘出现只读的解决办法

mount
blkid
sudo ntfsfix /dev/sdb1
mount -a

其他

卸载硬盘:

chen@ilaptop:/$ sudo umount /dev/sdb1

读写挂载硬盘

chen@ilaptop:/$ sudo mount -o rw /dev/sdb1

参考:https://jakting.com/archives/ubuntu-rw-windows-files.html

ppa源管理

在Ubuntu中,每个PPA源是单独存放在/etc/apt/sources.list.d/文件夹中的,进入到该文件夹,使用ls命令查询即可列出当前系统添加的PPA源。

shell 复制代码
sudo add-apt-repository ppa:ownername/projectname
sudo apt update
sudo apt install something

安装ImageMagic

  1. 安装:
shell 复制代码
sudo apt-get install imagemagick
  1. 测试:
    1). 版本察看
    简单地执行:
    引用
    convert -version

如果看到下面的信息说明安装已经成功
引用
Version: ImageMagick 6.4.3 2008-08-27 Q16 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2008 ImageMagick Studio LLC

2). 压缩图片.
当前目录下有一个文件名字叫hill.png,执行
引用
convert -sample 25%x25% hill.png hill_t.png

将缩小hill.png为原来的25%,生成新的文件名叫hill_t.png

如果出现如下错误提示:
引用
convert: error while loading shared libraries: libMagickCore.so.1: cannot open shared object file: No such file or directory

将so所在的路径加入到LD_LIBRARY_PATH(前面的安装方式默认安装so到/usr/local/lib目录下)
引用
export LD_LIBRARY_PATH=/usr/local/lib

当执行jpg图片缩放的时候,
3). 压缩jpg图片
引用
convert -sample 25%x25% water.png water_t.png

系统提示:
引用
convert: no decode delegate for this image format water.jpg'. convert: missing an image filename t_water.jpg'.

其他:

ImageMagick是一个免费的创建、编辑、合成图片的软件。

原文地址:https://blog.csdn.net/jacke121/article/details/76126245

Ubuntu20.04 中文显示不正确的解决方案

如下图是没有安装语言包的文件列表:

复制代码
drwxr-xr-x 11 root root  4096 Jun 14 09:52  ./
drwxr-xr-x  4 root root  4096 Jun 14 09:53  ../
-rwxr-xr-x  1 root root    18 Apr 28 22:24  .htaccess*
-rw-r--r--  1 root root    47 Oct 22  2020  .user.ini
drwxr-xr-x  6 root root  4096 May 23 22:21  app/
-rwxr-xr-x  1 root root   684 May  5 11:32  composer.json*
-rwxr-xr-x  1 root root 23126 Jun 10 22:57  composer.lock*
drwxr-xr-x  2 root root  4096 Jun  6 10:35  config/
drwxr-xr-x  2 root root  4096 Apr 28 22:24  extend/
-rwxr-xr-x  1 root root   506 Apr 28 22:24  max*
drwxr-xr-x  4 root root  4096 Jun 14 10:14  public/
drwxr-xr-x  2 root root  4096 Apr 28 22:24  routes/
drwxrwxrwx  4 root root  4096 Jun 12 14:36  storage/
drwxr-xr-x  8 root root  4096 Jun 14 10:47  vendor/
drwxr-xr-x  3 root root  4096 May 18 14:05  views/
drwxr-xr-x  2 root root  4096 Jun 12 05:51 ''$'\346\226\207\346\241\243'/

下面介绍下一般的解决办法:

首先安装语言包

复制代码
sudo apt-get install language-pack-zh-hans

安装完成后需要将我们的LANG设置为中文。

复制代码
locale -a 

上面命令查看安装的语言

复制代码
root@VM-0-10-ubuntu:/var/www/codeemo.cn# locale -a
C
C.UTF-8
POSIX
en_US.utf8
zh_CN.utf8
zh_SG.utf8

接下来

复制代码
export LANG=zh_CN.utf8

然后看下文件列表

复制代码
drwxr-xr-x 11 root root  4096 6月  14 09:52 ./
drwxr-xr-x  4 root root  4096 6月  14 09:53 ../
drwxr-xr-x  2 root root  4096 6月  12 05:51 文档/
drwxr-xr-x  6 root root  4096 5月  23 22:21 app/
-rwxr-xr-x  1 root root   684 5月   5 11:32 composer.json*
-rwxr-xr-x  1 root root 23126 6月  10 22:57 composer.lock*
drwxr-xr-x  2 root root  4096 6月   6 10:35 config/
drwxr-xr-x  2 root root  4096 4月  28 22:24 extend/
-rwxr-xr-x  1 root root    18 4月  28 22:24 .htaccess*
-rwxr-xr-x  1 root root   506 4月  28 22:24 max*
drwxr-xr-x  4 root root  4096 6月  14 10:14 public/
drwxr-xr-x  2 root root  4096 4月  28 22:24 routes/
drwxrwxrwx  4 root root  4096 6月  12 14:36 storage/
-rw-r--r--  1 root root    47 10月 22  2020 .user.ini
drwxr-xr-x  8 root root  4096 6月  14 10:47 vendor/
drwxr-xr-x  3 root root  4096 5月  18 14:05 views/

文档被显示出来了。

最后我将他添加到家目录下的.bashrc文件里

复制代码
export LANG=zh_CN.utf8

就可以一直正常显示中文了。

ubuntu开启messages log

less /etc/rsyslog.d/50-default.conf

复制代码
#*.=info;*.=notice;*.=warn;\
#       auth,authpriv.none;\
#       cron,daemon.none;\
#       mail,news.none          -/var/log/messages

删掉以上部分的注释,重启rsyslog

复制代码
service rsyslog restart

创建不需要密码就能登录的用户

添加一个密码为空的用户(sudo useradd -m 用户名),在 /etc/ssh/sshd_config 中设置 PermitEmptyPasswords yes 然后重启 ssh 服务(sudo systemctl restart ssh)

登录移除ubuntu各种提示

shell 复制代码
touch ~/.hushlogin
快来和小猫聊天吧~