【技术总结】常用Linux命令

硬盘管理

  • 查看各个目录得占用空间大小
    sudo du -shx *

  • 查看硬盘使用率
    df -h

批量Resize图像

convert -resize 50% <new_image>

ls | xargs -i convert {} -resize 50% …/resized/{}

find . -name ‘*.JPG’ | xargs -i convert {} -resize 30% resize_images/{}

Linux 开机自动启动某个服务

Ubuntu使用systemctl来管理开机启动服务。

因此首先得准备服务文件,后缀为.service
例如:

[Unit]
Description=Frp Client Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frpc -c /etc/frp/frpc.ini
ExecReload=/usr/bin/frpc reload -c /etc/frp/frpc.ini

[Install]
WantedBy=multi-user.target

有了该文件后,将该文件方法
lib/systemd/system/ 下面

启动
sudo systemctl start frps
自动启动
sudo systemctl enable frps

重启
sudo systemctl restart frps
停止
sudo systemctl stop frps
查看状态或者log
sudo systemctl status frps
移除自动启动
sudo systemctl disable frps

查看所有service
sudo systemctl list-unit-files

分卷压缩命令

每个分卷大小 2048M
7z a .7z <file_name> -v 2048m

文件大小查看

查看一级目录大小
sudo du -shx *

查看所有文件大小
sudo du -h

查看硬盘信息

查看所有系统硬盘
fdisk -l

查看硬盘占用率
df -h

硬盘永久挂载

  1. 创建挂载目录
    mkdir /home/data

  2. 手动挂载
    硬盘的名字,可以通过fdisk -l 查看
    mount </dev/xxx> /home/data

  3. 修改fstab
    vim /etc/fstab

file systemmount pointtypeoptionsdumppass
UUID=6a3ee0e5-f262-47b8-b26e-999eff585031/ext4errors=remount-ro01
/dev/sda/media/dataext4defaults01

如上所示是常见的fstab的格式,我们可以用UUID或者硬盘名来挂载,但是通常建议使用UUID,因为UUID无论如何插拔都保持不变。

如何查看UUID等信息呢?
sudo blkid /dev/sda
查看UUID/LABEL等信息

查看sudo执行记录

如果是基于debian的系统比如ubuntu或者linuxmint可以使用该命令查看。

sudo grep sudo /var/log/auth.log

批量拷贝和重命名

#!/bin/bash

# The source directory where the images are stored
SRC_DIR="/path/to/source"

# The destination directory where the images will be copied
DST_DIR="/path/to/destination"

# Find all image files in the source directory by mime-type
find "$SRC_DIR" -type f -print0 | xargs -0 file --mime-type | grep -F 'image/' | cut -d ':' -f 1 |

# For each image file, do the following
while read -r IMG_FILE; do

  # Get the relative path of the image file from the source directory
  REL_PATH="${IMG_FILE#$SRC_DIR}"

  # Replace all slashes in the relative path with underscores
  NEW_NAME="${REL_PATH//\//_}"

  # Copy the image file to the destination directory with the new name
  cp "$IMG_FILE" "$DST_DIR/$NEW_NAME"

done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值