Linux常用

查看所有用户

cat /etc/passwd |cut -f 1 -d :

Linux 创建Swap交换分区

 mkdir -p /var/_swap_
 cd /var/_swap_
 #Here, 1M * 2000 ~= 2GB of swap memory
 dd if=/dev/zero of=swapfile bs=1M count=2000
 mkswap swapfile
 swapon swapfile
 echo "/var/_swap_/swapfile none swap sw 0 0" >> /etc/fstab
 free -m

Ubuntu任务栏放在底部

gsettings set com.canonical.Unity.Launcher launcher-position Bottom

查找软件的配置文件路径

cat /var/lib/dpkg/info/<package>.conffiles

格式化分区

mkfs -t ext4 -c /dev/sda3

系统备份

tar cvpzfP backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys /

家目录改为英文

export LANG=en_US
xdg-user-dirs-gtk-update

Ubuntu GUI开启Root登录

第一步:设置好root密码,sudo passwd root
第二步:gedit /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf
修改配置文件在最后加上:greeter-show-manual-login=true
第三步:重新启动
第四步:修改gedit /root/.profile,避免 错误提示为:Error found when loading /root/.profile stdin: is not a tty 的提示
在/root/.profile中添加 tty -s && mesg n

  • Ubuntu语言设置,汉语无法移动问题解决
    1.gedit /etc/default/locale
    2.LANG="zh_CN.UTF-8"
    LANGUAGE="zh_CN:zh"

命令行配置无线网络

wpa_passphrase SSID PASSWD > /etc/wifi.conf

wpa_supplicant -D nl80211 -i wlp2s0-c /etc/wifi.conf -B

对应有线网卡的配置,新增无线网卡配置
vim /etc/network/interfaces

极速创建大文件

10G文件创建:dd if=/dev/zero of=bigfile bs=1024k count=1 seek=10000

GPG 加解密

  • 加密,完成后会生成加密文件file.gpg:gpg --passphrase your_passowrd -c file
  • 解密,完成后输出file机密文件:gpg --passphrase your_passowrd -o file -d file.gpg

静态IP

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s25
iface enp0s25 inet static
address 192.168.1.88
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameserver 192.168.1.1

netplan

network:
  version: 2
  renderer: networkd
  ethernets:
    ens18:
     dhcp4: no
     addresses: [10.1.50.226/24]
     gateway4: 10.1.50.254
     nameservers:
       addresses: [223.5.5.5,8.8.8.8]

生效:netplan apply

CentOS 配置静态IP

vim /etc/sysconfig/network-scripts/ifcfg-eth0

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=8f7424ba-a218-4e75-89ad-08df1155a403
DEVICE=eth0
ONBOOT=yes
IPADDR=10.1.50.221
NETMASK=255.255.255.0
GATEWAY=10.1.50.254
DNS1=223.5.5.5

禁用自动更新

(1)

systemctl stop apt-daily.service
systemctl stop apt-daily.timer
systemctl stop apt-daily-upgrade.service
systemctl stop apt-daily-upgrade.timer
systemctl disable apt-daily.service
systemctl disable apt-daily.timer
systemctl disable apt-daily-upgrade.service
systemctl disable apt-daily-upgrade.timer

(2)修改自动更新程序的配置文件也可以,同时更新 /etc/apt/apt.conf.d/10periodic /etc/apt/apt.conf.d/20auto-upgrades,将其值改为0

批量添加用户

注意:下面的脚本适用于中文环境,exp_continue作用是继续执行

#!/bin/bash
password=123456
for name in fanxulong qidenghui hanzhipeng qianxuerong yangyijun jiangwei chenfang yanbin zhaohongchuan geruliang
  do /usr/bin/expect <<EOF
    set time 30
    spawn  adduser $name
    expect {
        "*: " { send "$password\r"; exp_continue }
        "*: " { send "\r"; exp_continue }
        "是否正确" { send "y\r" }
    }
    expect eof
EOF
done

生成PDF大文件

原理是复制成多页文件,所以原文件最好尽量大,这样生成的速度较快
pdftk $(for i in $(seq 1 100); do echo -n "10MB.pdf "; done) cat output 1_GB.pdf

获取deb及依赖包,以wget为例

ubuntu

PACKAGES="wget"
apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests \
  --no-conflicts --no-breaks --no-replaces --no-enhances \
  --no-pre-depends ${PACKAGES} | grep "^\w")

CentOS

yum install --downloadonly --downloaddir=/root/rpm/wget wget
rpm -Uvh /root/rpm/wget/*.rpm --nodeps --force

CentOS自动联网安装本地包依赖

yum -y localinstall *.rpm

查找当前目录下N天修改的文件

for file in find $PWD -type f -mtime -87 ; do echo $file ; done

SS.R__V.2ray安装脚本

  • https://raw.githubusercontent.com/Miuzarte/hijk.sh/main/Original/ssr.sh
  • bash <(curl -s -L https://git.io/v2删除这该死的敏感字ray.sh)

获取JDK路径

ls -l /etc/alternatives/java | awk '{print $11}' | awk -F 'jre' '{print $1}'

wget 下载文件的正确姿势,资源地址要习惯性的用引号包裹

  • wget --content-disposition "资源地址"

kill多个包含某关键字的进程

  • ps -ef|grep jar|grep dpms|grep -v grep |awk '{print $2}'|xargs kill -9

查看GLIBC版本

  • strings /usr/lib64/libstdc++.so.6 | grep GLIBC

安装Nvidia驱动报The Nouveau kernel driver is currently in use by your system.

vim /etc/modprobe.d/blacklist-nouveau.conf
blacklist nouveau
options nouveau modeset=0
update-initramfs -u
reboot

docker-compose V2安装

DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
wget https://gh.con.sh/https://github.com/docker/compose/releases/download/v2.17.3/docker-compose-linux-x86_64
mv docker-compose-linux-x86_64 $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose

docker 启动smb服务

docker run -it --name samba -p 139:139 -p 445:445 -v /mnt/data/src/DeepMosaics:/mount -d dperson/samba -u "eric;123456" -s "shared;/mount/;yes;no;no;eric;eric;eric"

CentOS8 更换源

  • mv /etc/yum.repos.d /etc/yum.repos.d.bak
  • cd /etc/yum.repos.d;rm -fr ./*
  • 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

Linux安装字体

  • yum install fontconfig mkfontscale -y
  • Win字体路径:C:\Windows\Fonts
  • 复制对应字体至目录:/usr/share/fonts/self
  • 生成索引:mkfontscale
  • 验证安装结果:fc-list :lang=zh
  • 对应的服务,重启才会生效

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x000000009f280000, 54001664, 0) failed; error='无法分配内存' (errno=12)

vm.max_map_count = 262144
vm.overcommit_memory = 1
  • 生效:sysctl -p

Rocky9 使用EPEL

dnf config-manager --set-enabled crb
dnf install epel-release

nmcli配置IP

  • DHCP自动获取:nmcli con mod ens18 ipv4.method auto && nmcli con up ens18

  • 静态:nmcli con mod ens18 ipv4.address 192.168.123.100/24 ipv4.gateway 192.168.123.1 ipv4.dns 223.5.5.5 connection.autoconnect yes

posted @ 2023-03-23 14:57  秒年度  阅读(78)  评论(0编辑  收藏  举报