硬盘管理
-
查看各个目录得占用空间大小
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
硬盘永久挂载
-
创建挂载目录
mkdir /home/data -
手动挂载
硬盘的名字,可以通过fdisk -l 查看
mount </dev/xxx> /home/data -
修改fstab
vim /etc/fstab
file system | mount point | type | options | dump | pass |
---|---|---|---|---|---|
UUID=6a3ee0e5-f262-47b8-b26e-999eff585031 | / | ext4 | errors=remount-ro | 0 | 1 |
/dev/sda | /media/data | ext4 | defaults | 0 | 1 |
如上所示是常见的fstab的格式,我们可以用UUID或者硬盘名来挂载,但是通常建议使用UUID,因为UUID无论如何插拔都保持不变。
如何查看UUID等信息呢?
sudo blkid /dev/sda
查看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