linux 命令memo
uuidgen
生成uuid
history
命令行历史
修改history容量,~/.bashrc
最后追加
export HISTSIZE=10000
export HISTFILESIZE=10000
df du
# 查看磁盘占用
df -h
# 查看文件夹大小
du -h -d 1
# 排序
du -m -d 1 | sort -n
# ping服务器的特定端口
nc -vz 192.168.0.1 22
shell文件中的脚本生成的文件名末尾有一个问号
检查换行符是否是\n,如果是\r\n需要替换
批量修改文件名
rename 's/^Pre/Post/' *
rename 's/^\D+(\d+)\D+/$1/' *
rename 's/^\D+([cp]\d+.+)/$1/' *
for f in * ; do mv — "$f" "PRE_$f" ; done
counter=1; for file in *; do [[ -f $file ]] && echo mv -i "$file" PRE_$(printf '%02d' $counter).zip && ((counter++)); done
简单加密文件名
# 不加密后缀
for file in *; do
[ -f "$file" ] || continue
mv -- "$file" "$(printf "%s" "${file%.*}" | base32).${file##*.}"
done
# 解密
for file in *; do
[ -f "$file" ] || continue
mv -- "$file" "$(printf "%s" "${file%.*}" | base32 -d).${file##*.}"
done
# 加密后缀
for file in *; do
[ -f "$file" ] || continue
mv -- "$file" "$(printf "%s" "${file}" | base32)"
done
# 解密
for file in *; do
[ -f "$file" ] || continue
mv -- "$file" "$(printf "%s" "${file}" | base32 -d)"
done
创建软连接
# 磁盘满的时候,使用软连接把老数据转移到别的硬盘上个人觉得也是个办法,
# 就是不知道客户为什么说不稳定
ln -s [真实磁盘路径] [连接所在位置]
命令行内容输出到剪贴板
# git bash(windows)
find . -typf f | clip
# linux
find . -typf f | | xclip -selection clipboard
# or
alias clip='xclip -selection clipboard'
find . -typf f | clip
查看linux用户所在组
groups
groups tom
# 添加用户到某个组
sudo usermod -a -G groupname username
修改系统时区
# 检查当前时区
timedatectl
# or
ls -l /etc/localtime
# 检查时区列表
timedatectl list-timezones
# 修改时区
sudo timedatectl set-timezone America/New_York
# 没有timedatectl组件时(比如docker)
sudo rm -rf /etc/localtime
sudo ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
sudo echo 'America/New_York' > /etc/timezone
解析url时指定dns
nslookup isc.org 8.8.8.8
查看占用端口号的进程
# linux
lsof -i :8080
# windows git bash
netstat -ano | grep 8080
ftp命令使用
# 进入ftp
ftp
# 连接ftp, 接着输入账号密码
open 192.168.1.2
# 下载文件
get a.txt
# 上传文件
put /path/b.txt /ftppath/b.txt
unzip
# 解压时指定字符编码
unzip -O shift-jis ~/Downloads/【新入荷ECM】資料.zip
# rar的话没找到, 可以在virtualbox里装个日文版win7里解压
reference
- How to change history size for ever?
- why questionmark comes in the end of filename when i create .txt file through shell script?
- Add Prefix-Suffix To All Existing Files in Linux Directory
- How do I Ping a Specific Port?
- Bash - Rename files to base64 value of the filenames
- Base64 Encoding safe for filenames?
- Linux运用软链接解决目录空间不足
- How To Copy Command Output To Linux Clipboard Directly
- Linux Show The Groups a User Is In
- How to Set or Change the Time Zone in Linux | Linuxize
- date - Docker Container time & timezone (will not reflect changes) - Server Fault
- How to specify a DNS server in nslookup?
- How to Download and Upload Files using FTP Command Line
- ftp put | Microsoft Learn
- encoding - How to unzip a Japanese ZIP file, and avoid mojibake/garbled characters - Ask Ubuntu
Updated: 2025-03-06 22:35
Created: 2022-11-10 20:00