ls / | grep -v proc | while read l; do count=$(find /$l/ -type f -print | wc -l); echo "/$l: $count"; done
Bonus: Đếm số file trong một thư mục bất kỳ
Ví dụ: /data/docker
dirparent="/data/docker";
find ${dirparent} -maxdepth 1 -type d | tail -n +2 | while read l; do count=$(find ${l}/ -type f -print | wc -l); echo "${l}: ${count}"; done | sort -k2 -n
tail -n 10 file.txt | head -n1
## Or using sed
sed -n 10p file.txt
tail -n +10 file.txt
grep -A 5 'pattern' /tmp/file.txt
ls | while read l; do new=$(echo $l | tr '[:upper:]' '[:lower:]'); mv $l $new; done
- Unmount phân vùng
- Kiểm tra phân vùng đang tồn tai
# parted /dev/vdb
> print
- Chọn phân vùng và thay đổi không gian (VD: Phân vùng
1
và tăng tối đa kích thước không gian)
> resizepart 1 -1
> quit
- Thay đổi kích thước phân vùng:
- Với các định dạng ext3, ext4
e2fsck -f /dev/vdb1
resize2fs /dev/vdb1
- Với xfs
xfs_growfs -d /dev/vdb1
curl -sL https://bootstrap.pypa.io/get-pip.py | python
atop -r /var/log/atop/atop_XXXXXXXXX -b 15:00 -e 15:30
Xem lại lịch sử sử dụng tài nguyên trong khoảng thời gian từ 15:00 -> 15:30 Với tùy chọn:
-r
: Đọc file. Mặc định lưu trữ tại/var/log/atop
-b
: Thời gian bắt đầu-e
: Thời gian kết thúc
Lọc thông tin với phím tắt sau:
m
: Xem thông tin về Memoryd
: Xem thông tin về Disk;n
: Xem thông tin về Network;v
: Lọc các tiến trình; loại bỏ các tiến trình giống nhauc
: Xem câu lệnh của tiến trình.
Tham khảo:
- https://haydenjames.io/use-atop-linux-server-performance-analysis/
- https://www.2daygeek.com/atop-system-process-performance-monitoring-tool/
- https://haydenjames.io/use-atop-linux-server-performance-analysis/
Xem thông tin user đã có trên hệ thống:
Tìm kiếm chính xác:
select user,host,authentication_string from mysql.user where user='user1';
-> Chú ý: Với bản MySQL < 5.6, thay thế authentication_string
thành password
.
Tìm kiếm tương đối:
select user,host,authentication_string from mysql.user where user like '%user1%';
- Xác định chính xác thông tin quyền hạn, host, CSDL, bảng biểu,...
- Chỉ cho phép 20 kết nối/user
Ví dụ:
GRANT USAGE ON database.table TO 'user1'@'host1' IDENTIFIED BY 'passw0rD' WITH MAX_USER_CONNECTIONS 20;
- Với password hash có sẵn:
GRANT USAGE ON database.table TO 'user1'@'192.168.2.251' IDENTIFIED BY PASSWORD '*XXX' WITH MAX_USER_CONNECTIONS 20;
CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
RENAME USER old@1.2.3.4 TO new@1.2.3.5
Mẫu như sau:
[client]
user = root
password = 'YBKw4'
host = 10.5.0.81
port = 33066
pt-show-grants --only user1@192.168.2.111
Lỗi:
mydumper: error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory
Khắc phục:
wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5.6_amd64.deb
apt install ./libssl1.0.0_1.0.2n-1ubuntu5.6_amd64.deb
https://askubuntu.com/a/1344529
ufw status
- Mở một port cố định
ufw allow 3306/tcp
- Mở range port
ufw allow 6000:6007/tcp
- Cho phép dải IP được phép sử dụng port 3306
ufw allow from 15.15.15.0/24 to any port 3306
- Cho phép truy cập từ địa chỉ xác đinh đến 3306
ufw allow from 15.15.15.15 to any port 3306 proto tcp
- Chặn truy cập từ địa chỉ IP xác định
ufw deny from 15.15.15.14