Linux
Linux 常用
1、创建root权限的非root用户
# 添加设置用户
adduser lxs
passwd lxs
# 升权,加入配置
chmod 777 /etc/sudoers
vim /etc/sudoers
写入:lxs ALL=(ALL) NOPASSWD:ALL
# 还原权限。不还原,root 权限的非 root 用户,将不生效
chmod 440 /etc/sudoers
2、时间同步
# 检查时区
timedatectl status|grep 'Time zone'
# 设置硬件时钟调整为与本地时钟一致
timedatectl set-local-rtc 1
# 设置时区为上海
timedatectl set-timezone Asia/Shanghai
# 安装ntpdate
yum -y install ntpdate
# 同步时间
ntpdate -u pool.ntp.org
# 检查
date
3、换行符转换
-
Windows 换行符:\n\r
-
Linux 换行符:\n
# 当 vim 出现 ^M 字符,或执行脚本出现 \r 时,在 vim 编辑器下使用: # 使用 Linux 换行符 :set ff=unix # 使用 Windows 换行符 :set ff=dos
4、curl
# -I:查看 header 头信息
# -L:显示完整 location
# -b:设置 cookie
curl 'http://127.0.0.1:8881/uri' -I -L -b 'COOKIE_KEY=COOKIE_VALUE'
N、order
- 查看服务器运行时间
- date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"
- 计算文件大小
- du -sh test.txt
- scp 非标端口
- scp -P 2223 root@127.0.0.1:/test.zip .
- IP
- 公网ip:
- curl myip.ipip.net
- curl -L ip.tool.lu
- 内网ip:ifconfig(默认显示内网ip,无内网IP则显示公网ip)
- 查看带宽:sudo ethtool eth0(ifconfig第一个)