A series of common problems for Linux novices

In this article,
I use deepin linux in the continuous update . The following method is a quick solution. If you want to know more or the reasons, please do it yourself. Use Google to read English literature.

Set up swap file (swapfie) under Linux system

When the system memory is not enough, the swap partition releases part of the physical memory space for the currently running program. When installing the linux system, you can directly divide a swap partition, or you can install it in the system. Then create a swapfile file on a disk instead.
The steps are given below

  1. Create swap file-swapfile
sudo fallocate  -l 6G /var/swapfile

Created a 6G swapfile in the var directory
3. Change /swapfile permissions

sudo chmod 600 /var/swapfile

The permission to modify the swapfile file is 600, that is, the root user can read and write, and other combined users have no permission.
4. Format as swap

sudo mkswap /var/swapfile
  1. Make the above settings take effect
sudo swapon /var/swapfile
  1. In order to automatically mount swap in the future, add it to /etc/fstab
sudo vi /etc/fstab

At this time, press any one of the three lowercase letters i, a, o to enter the edit mode, so that you can write. Copy the following content into it, pay attention to copy and paste ctrl + shift + c and ctrl + shift + v, not ctrl + c, ctrl + v operation

/var/swapfile  none  swap  defaults 0 0

After writing, press esc, then press :x to save and exit.
Below is my screenshot.
Insert picture description here
Your file may contain several more lines than mine. Don't worry about this, just copy it.
7. If you are not satisfied with this /swapfile, for example, if you want to change the size, you can use
sudo swapoff -a to turn off the swap
sudo rm -f /swapfile to delete the current swapfile
. Start with the first step, and go again.
Use the free command to view the effect of the settings
Insert picture description here

Why does my hard disk still have space, but part of it cannot be used?

My /dev/sdb7 hard disk 265G uses 247G, but I can’t store anything anymore. Obviously there is enough space
because the ext4 system reserves 5% of space for super users by default, which can be used.

sudo tune2fs -m 0.1 /dev/sdb7

Set this 5% to 0.1%, and you can continue to save things again.
Of course, there are many reasons for this situation, and I just mentioned the one I encountered.

ROOT users of deepin system are not automatically completed by pressing tab

sudo vim /etc/bash.bashrc

2. Uncomment the following and remove #

#if [ -f /etc/bash_completion ]; then
#. /etc/bash_completion
#fi

3. Put

source /etc/bash.bashrc

Append to /etc/profile, it will run this command every time you boot.

Common commands for software packages

sudo apt update         更新软件包,并提醒是否安装
sudo apt upgrade        升级本地软件

The above two are frequently used and the most used are mainly used for upgrading. If you install the software and prompt that there is insufficient dependency, you can execute the above two instructions and restart the computer.
Note that when using the sudo command system, you will be asked to enter the administrator password. Most of the passwords are not prompted under linux, unlike windows that will use **** to remind you to enter several passwords. Just enter it and press Enter

install software

sudo apt install <包名>

For example, I install Firefox

sudo apt install firefox

After installing the software, the software installation package is not deleted, you can use the following command to delete the downloaded installation package

sudo apt autoclean                       清理未安装软件的安装包
sudo apt clean      	                    清理所有安装包

Uninstall software

sudo apt purge <包名>

How do I know which packages I have installed?

What if I know that I have installed Baidu Netdisk, but I don't know his full name, and I only know that the package name contains baidu? You can use the second instruction below

dpkg -l 		   		列出所有安装的包
dpkg -l | grep -i baidu  在所有的包里查找名字里含有baidu的包并显示出来
				        -i的意思是匹配baidu时忽略大小写。

After finding the package name, you can sudo apt purge <package name>

Delete software configuration files

You may notice that when using dpkg -l, most of the leftmost software listed are ii signs, and some are rc signs. ii means that the package is installed, rc means that the package is uninstalled but the configuration remains.
use

dpkg -l |grep ^rc              #注释rc前面加^表示找出以rc开头的内容

Sentence to check if there are such remnants. If there is no output from your terminal, it means that there is no such software. If you execute the following sentence to clean it up completely, as for how the following sentence is implemented, I won’t explain it here. Novice.

dpkg -l | grep '^rc' | awk '{print $2}' | sudo xargs dpkg --purge

A software installation package of the linux system depends on some small packages to run normally. Suppose I installed Google Chrome and Firefox browser at the same time, and they also depend on a small package named a. When I uninstall these two browsers, this small package a will no longer be used by other packages, then it becomes Lonely bag, like an orphan. There may be many package systems like this, most of which are generated after the software is uninstalled. You can use the following command to uninstall these lonely packages. Still the same. If there is no output from the terminal, it means that there is no orphan package.

sudo apt autoremove

The following is a supplement to grep, you can ignore it

grep用于匹配文件里面的内容,和find有所区别。grep是用正则号,而find是用用通配符

. 表示任意一个字符。
在grep “c*” file表达式中,*前面添加单个的任何字符都没有意义(显示所有内容)。
grep "cc*"显示所有含c的行,(所有的c都高亮)
grep "ccc*"匹配所有含cc的行

grep [abc] file :只要一行含有abc中的任意一个字符,那么显示这一行(所有abc高亮)
[a-zA-Z] :表示匹配一个字符,这个字符必须是a-z或A-Z这52个字母中的一个。
[^123] :匹配一个字符,这个字符是除了1、2、3以外的所有字符。

对于一些常用的字符集,系统做了定义:
[A-Za-z] 等价于 [[:alpha:]]
[0-9] 等价于 [[:digit:]]
[A-Za-z0-9] 等价于 [[:alnum:]]
tab,space 等空白字符 [[:space:]]
[A-Z] 等价于 [[:upper:]]
[a-z] 等价于 [[:lower:]]
标点符号 [[:punct:]]

du instruction

Sort the current directory, including hidden and unhidden files (only display the current folder and files, not subdirectories)

du -sh .[!.]*  *  |sort -nr

Bulk copy

find. -name “*log”|xargs -t -i cp {} /home/hadoop/logs/
. . . To be continued

Guess you like

Origin blog.csdn.net/qq_35543026/article/details/105510359