查看系统中有哪些用户
cut -d : -f 1 /etc/passwd
查看可以登录系统的用户
cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1
查看系统中有哪些用户组
cut -d : -f 1 /etc/group
查看可以登录系统的用户组
cat /etc/group | grep -v /sbin/nologin | cut -d : -f 1
查看用户操作:w命令(需要root权限)
查看某一用户:w 用户名
查看登录用户:who
查看用户登录历史记录:last
修改root用户密码:passwd
root用户修改其他用户密码:passwd <user_name>
添加用户:adduser [用户名]
删除用户:userdel [用户名]
添加用户组:groupadd [组名]
删除用户组:groupdel [组名]
查看某个程序进程
ps -aux|grep java
杀死进程 kill -9 pid号
查看端口 lsof -i:端口号
查看某个文件 tail -f xxx
删除某个文件 rm xx
删除文件夹 rm -rf xxx
centos 7 更改时区
# 删除当前时区文件
rm -f /etc/localtime
# 创建新的时区文件
ln -s /usr/share/zoneinfo/UTC /etc/localtime
# 时区信息
timedatectl
# 当前时间
date
设置时间
hwclock --set --date="2023-12-20 14:14"
hwclock --hctosys
clock -w
系统重启
shutdown -r now
systemctl stop firewalld.service 关闭防火墙
systemctl start firewalld.service 启动
systemctl status firewalld.service 查看状态
# 开放tcp端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
# 开放端口段
firewall-cmd --zone=public --add-port=3000-4000/tcp --permanent
# 查看所有开放端口
firewall-cmd --zone=public --list-ports
# 启动
systemctl start firewalld
# 重启 设置端口后一定要重庆防火墙!!!
systemctl reload firewalld
查看磁盘大小
df -h
# 查找超过 800M的文件
find . -type f -size +800M
# 查找超过 800M的文件 以及文件信息
find . -type f -size +800M -print0 | xargs -0 ls -l
# 查找超过 800M的文件 以及文件信息具体位置
find . -type f -size +800M -print0 | xargs -0 du -h
# 查找超过 800M的文件 以及文件信息具体位置 按照大小排序
find . -type f -size +800M -print0 | xargs -0 du -h | sort -nr
查找文件
find / -name *.cookie
授权 chmod +x 文件名
chmod +x install-prepare.sh
zip 命令
1、把/home目录下面的data目录压缩为data.zip
zip -r data.zip data #压缩data目录
2、把/home目录下面的data.zip解压到databak目录里面
unzip data.zip -d databak
3、把/home目录下面的a文件夹和3.txt压缩成为a123.zip
zip -r a123.zip a 3.txt
4、把/home目录下面的t.zip直接解压到/home目录里面
unzip t.zip
5、把/home目录下面的a1.zip、a2.zip、a3.zip同时解压到/home目录里面
unzip a*.zip
6、把/home目录下面w.zip里面的所有文件解压到第一级目录
unzip -j wt.zip
nc 命令
1、检测端口是否通
nc -vz IP 地址或域名 端口
nc -vz 172.168.30.131 28201
find 命令
1、根路径下查找扩展名为.log文件
find / *.log
2、当前目录下查找 kernel.log 文件中含有 token time invalid 值的文件信息 并分页展示
find -name kernel.log|xargs grep 'token time invalid'|less
linux文件dos转unix格式
linux 环境下
1、vi 打开文件,查看文件格式
:set ff
你会发现其格式是dos的
2、设置文件格式为 unix 在vi模式下
:set ff=unix
enter 键 之后 :wq 保存即可
3、若不放心可以在vi模式下使用 :set ff 再次查看现在文件格式
linux 查看软件是否安装
rpm -qa | grep software_name
安装软件
rpm -i xxxxx
卸载软件
rpm -e [package_name]
只下载软件 到 /opt 目录
yum install --downloadonly --downloaddir=/opt ntp