});

Funda of Linux

All about Linux here

Handy workflows

Download plain text scripts from git dir

  1. Click the raw button for a random scripts in that folder with format like:
    https://raw.githubusercontent.com/*
  2. Save that to a prefix.txt file, and save list of scripts names into files.txt
  3. Use the code to iterate all lks.txt, append prefix then use wget to download.
    for ln in $(cat files.txt); do printf "%s%s\n" "$(cat prefix.txt)" "$ln"| xargs wget; done;

command info search

Linux内存管理与扩容

内存管理

全局占用查看

【df命令详解】

逐层查看内存

删除日志文件

运行过程中产生的日志,本次删除的是var/spool/abrt</em></strong> 中的ccpp-2020-11-28-14:52:27-3689</strong></em> 日志文件,大小4.7G。

按照解释,/spool目录下多为mails, news和运行日志,而abrt是Automatic bug report tool的缩写,系统错误日志可以在core中找到。

删除操作如下(也可见后文)

linux内存管理知识

各英文缩写的解释如下:

Abbrev.NameDefine
LVMLogic Volume Manager逻辑内存管理器
PVPhysic Volume物理内存
VGVolume Group根据物理内存分成的内存组
LVLogic Volume逻辑内存

硬盘挂载流程

硬盘挂载流程
可以直接分区后就格式化,也可以借助LVM。
LVM的优势就是多了一层Virtual Group加工,让后期的内存分配更加灵活(而非Logic Group直接与Physical Volume 关联)。

借助LVM的内存管理机制:

Physical Volume将被格式化为基本单元,划分到不同的Virtural Group中,实际划分Logic Group时再统一从Virtual Group中调用内存。
LVM管理

参考:

  1. 流程图解析Linux 分区和LVM挂载,带流程图解析

  2. 表格形式列出Linux内存管理涉及的各种指令Linux磁盘分区与LVM详解

实战:linux硬盘扩容

Linux公社多图细致解析:https://www.linuxidc.com/Linux/2019-04/158346.htm
涉及流程基本一致,连接物理盘,采用LVM识别常见PV,转化为VG,分配到LV
格式化后将LV分配给现有对应路径下。
使用虚拟机的朋友注意:shared entities 无法expand,离线设置后方可上线。
可以使用lsblk展示当前分区情况

File Management

删除文件/文件夹

Packages

查找安装列表

yum list installed | grep 关键字
命令匹配过滤
可支持通配符

卸载

yum remove [package name]
仅支持删除单个包,删除时需要输入全称
但会自动卸载关联包

批量卸载

参考链接
rpm -qa | grep [包名] |xargs rpm -e --nodeps
解释:

  • rpm -qa 用 rpm查找所有包
  • rpm -e 卸载 --nodeps 仅卸载当前,不考虑依赖
  • xargs Extended Arguments
    形成pipeline传递前一步返回参数(stdin),加工后(分批etc)传递下一级
    常用于批量执行命令,类似于传话筒
    扩展阅读:cnblogs的详细说明

查找文件

find 命令简介

关于:为何要加单引号

批量移动/重命名文件

复制就是cp
-t应该是 to的意思,指定结果的
如果是到某个目录下,可以用’/’结尾

Ref: CSDN-Copy and Move

count files

zip and unzip

link

usually refers to symlink: symbol link or soft link
ln -s %target_file_path %link_path
delete the link by
unlink %link_path

soft v.s. hard

Soft link is like shortcut in windows. It will be invalid if target file is removed. It is a door to the key.
Hard link more like mirroring, it points to the inode (fundamental database). It is another key to the door.

SHARCNET Skills

  1. command diff can distinguish the files, useful in version check
  2. Resource manager top, press q> to quit
  3. Append alias lm="load modulus -i" in ~/.bashrc to set custom command.

alias

  1. temporary alias, can run alias shortcode='full code'
  2. permanent alias can do

text pipeline

裁剪

裁剪命令
| tr "\n" "\0" | xargs -d"\0"
tr = truncating删减
此处匹配的是逐字符串匹配 ‘@anaconda’

批量匹配于修改

对于字符串匹配和批量修改,采用sed命令
sed -i 's/OldString/NewString/g' filename
注意该命令多用于文本文档内修改,
尝试用于xargs修改grep返回命令,失败。

permissions

vim

vim /etc/%YOUR_FILE% to view the file
Press a to insert content
Press Shift+; to activate command mode.
Enter qto quit, or wq to save and quit, or q! to force quit.

visual mode

for interactive response: {Link}

  • v for phrase mode, can also use w to start of line,
  • V for line mode, good for copy
  • Ctrl+b for block mode, good for indent check

Add users

Both useradd and adduser can do this. But former is in command form thus requires more options. The latter is preferred usually to avoid compatibility problems.

password change

bash

IP reading pipeline
use alias to give a allocate a nickname for a value, the value is wrapped in ” “.
Note that a ‘\’ placed before “$” escapes the “$”.
grep is a filter, like ‘findstr’ command in windows shell
awk is a batch operation software do the same operation line by line.
More about GNU awk see this: https://blog.csdn.net/jasonchen_gbd/article/details/54986434
the dollar mark ‘$’ is a regular expression like sign pointing to the instance at the fourth position.
Inspired by https://www.youtube.com/watch?v=PPQ8m8xQAs8, thanks for sharing.

bash scripts with nano

Visual Matlab on server

Forwarding Matlab GUI to local
CSDN – https://blog.csdn.net/davidsmith8/article/details/89409755

DOS output in UTF-8

Ref:{StackOverflow}

Linux Jobs Pipeline Design

  1. Use && connect the commands to force all line must succeed. ; only count on start or not. || indicate the tasks are alternative. {Link-2daygeek}
  2. Use pstree -p <pid> to check hierachy of process. More multi-thread command see {Link}
  3. Use & at the end of the line to run jobs background. jobs -l to list the pid and job#. {StackXchange}
  4. The wait <PID> and sleep <time> can be links between commands.
  5. A demo is here {Link-Baelung}
  6. The wait only works if the waited process is a child process of current process…

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.