Alice.tech

使用linux过程中的常识

环境变量 系统级 用户级 会话级 用户创建 模糊查询 打印日志 文件修改 sed 同时修改重复的内容 i 直接修改 s 替换命令 g global全局 vim/nvim Curl curl十分方便,对于临时检查网页内容 …

环境变量

系统级

/etc/environment          # PAM 模块读取,格式简单:KEY=VALUE
/etc/profile              # 所有用户的 login shell 执行
/etc/profile.d/*.sh       # /etc/profile 会遍历这个目录下的脚本
/etc/zsh/zshenv           # 系统级 zsh 配置
/etc/security/pam_env.conf  # PAM 环境变量配置

用户级

~/.profile                # 用户 login shell 执行
~/.zshrc                  # zsh 交互式 shell 执行
~/.zshenv                 # zsh 所有 shell 执行(最先加载)
~/.zprofile               # zsh login shell 执行

会话级

~/.xprofile               # X11 图形登录时执行
~/.xinitrc                # startx 时执行
~/.wayland-environment    # Wayland 环境
/etc/X11/Xsession.d/*     # 系统级 X 会话脚本

用户创建

adduser name  ##交互创建 
usermod -aG sudo name  ##加入sudo

模糊查询

打印日志

hja h a

文件修改

sed

同时修改重复的内容

-i 直接修改 s 替换命令 g global全局

sed -i 's/apple/banana/g' test

vim/nvim

:%s/apple/banana/g

Curl

curl十分方便,对于临时检查网页内容 ,下载脚本 more……

列举一些自己常用的

curl -

tar

对于文件的清理,归档 归档 归档

linux 下把 归档 与 压缩分开了,tar 只负责归档 , gzip bzip2 xz 负责压缩

归档

1.创建归档文件,把文件file1 file2 directory 打包到 archive.tar 的归档文件

tar -cvf archive.tar file1 file2 directory

2.解压归档文件,解压名为 archive.tar 的归档文件,还原其中包含的文件和目录

tar -xvf archive.tar

压缩

1.压缩归档文件,将名为 directory 的目录打包成一个归档文件,然后使用 gzip/bzip2/xz 进行压缩,生成名为 archive.tar.gz 的文件

tar -czvf archive.tar.gz directory  //gzip
tar -cjvf archive.tar.bz2 directory  //bzip2
tar -cJvf archive.tar.xz directory  //xz

2.解压时可以省略算法参数

tar -xvf any_one.tar.gz/bz2/xz

iptables开放端口

sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

acme.sh 的使用

爱国仓库

git clone https://gitee.com/neilpang/acme.sh.git

fish

添加环境变量

echo 'set -gx PATH $PATH ~/.acme.sh' >> ~/.config/fish/config.fish
source ~/.config/fish/config.fish
acme.sh --version
chsh -s /usr/bin/fish
usermod -s /usr/bin/fish root

软链接

创建软链接的命令

ln -s 源文件绝对路径 链接文件绝对路径

在一些需要多处重复使用文件场景好用

2026.05.07 不知道发生了什么根目录下的 软连接目录 /bin 无了😒,待我弄清楚

sudo ln -sF /usr/bin /bin

网络配置

sshd修改

sudo vim /etc/ssh/sshd_config  ##修改sshd配置
PermitRootLogin no        ##禁止ssh登入root账户
PasswordAuthentication no ##禁用密码登入
PubkeyAuthentication yes  ##启用对钥

把公钥复制到 ~/.ssh/authorized_keys

如果没有

ssh-keygen -t ed25519   ##生成一个

网络接口

类型 名称 作用
本机 lo 用于本地服务的通信,127.0.0.1 ::1 就是它
主板硬件网卡 enp,eno,ens,enpXsY 物理网卡 ,例如我的 usb扩展网卡 enp3s0f3u2u4c2 ,
docker 网络 docker0 为容器提供nat服务,类似交换机,负责容器间的通信
wifi无线网卡 wlp1s0 无线网络
虚拟网桥 br-xxxxxxxxxx 自己创建的虚拟网桥,如 pods servise 通信使用
虚拟网卡 vethxxxxxx 连接容器与网桥
vpn / 覆盖网络 tun wg tailscale zt 虚拟局域网 或 VPN
vlan虚拟接口 ens3.100 网卡ens3上id为100的虚拟接口,可以在一条物理链路上分离流量
网卡绑定 bond/team 类似把两条网线合并,提示带宽和余

修改vlan

修改 /etc/network/interfaces 文件 , 我这里定向到了旁路由

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto ens18
iface ens18 inet static
    address 192.168.10.32
    network 255.255.255.0
    gateway 192.168.10.114
    dns-nameserver 192.168.10.114 114.114.114.114

轻量系统

alpine

openwrt

硬件信息

ubus call system board      ## 查看基本信息

原始笔记:linux/base.md