CentOS是一个基于Red Hat Enterprise Linux(RHEL)源代码的开源Linux发行版。以下是一些在CentOS系统中常用的命令:
ls - 列出目录内容
ls -l # 以长格式显示
ls -a # 显示所有文件,包括隐藏文件
cd - 更改当前目录
cd /path/to/directory # 进入指定目录
cd ~ # 返回用户主目录
cd - # 返回上一个目录
pwd - 显示当前工作目录
pwd
cp - 复制文件或目录
cp source destination # 复制文件
cp -r source destination # 递归复制目录
mv - 移动或重命名文件或目录
mv oldname newname # 重命名文件
mv file directory/ # 移动文件到目录
rm - 删除文件或目录
rm file # 删除文件
rm -r directory # 递归删除目录
mkdir - 创建新目录
mkdir directory
rmdir - 删除空目录
rmdir directory
touch - 创建空文件或更新文件时间戳
touch file
cat - 显示文件内容
cat file
more / less - 分页显示文件内容
more file
less file
head - 显示文件开头内容
head file
tail - 显示文件结尾内容
tail file
tail -f file # 实时跟踪文件更新
grep - 在文件中搜索文本
grep "text" file
find - 在目录中查找文件
find /path/to/search -name filename
chmod - 更改文件权限
chmod 755 file
chown - 更改文件所有者
chown user:group file
df - 显示磁盘空间使用情况
df -h # 以人类可读的格式显示
du - 显示目录空间使用情况
du -sh directory # 显示目录总大小
ps - 显示当前进程状态
ps aux # 显示所有进程的详细信息
top - 实时显示系统进程和资源使用情况
top
kill - 终止进程
kill PID # 终止指定PID的进程
kill -9 PID # 强制终止进程
tar - 打包和解包文件
tar -czvf archive.tar.gz directory # 打包目录
tar -xzvf archive.tar.gz # 解包文件
wget - 从网络下载文件
wget http://example.com/file
curl - 用于传输数据
curl http://example.com
yum / dnf - 包管理器
yum update # 更新所有包
yum install package # 安装包
dnf install package # 使用DNF安装包(CentOS 8+)
systemctl - 系统和服务管理
systemctl start service # 启动服务
systemctl stop service # 停止服务
systemctl restart service # 重启服务
systemctl enable service # 设置开机自启
systemctl disable service # 禁用开机自启
firewall-cmd - 防火墙管理(CentOS 7+)
firewall-cmd --list-all # 列出所有防火墙规则
firewall-cmd --add-service=http --permanent # 添加HTTP服务
firewall-cmd --reload # 重新加载防火墙配置
hostnamectl - 主机名管理(CentOS 8+)
hostnamectl set-hostname new-hostname
timedatectl - 时间和日期管理
timedatectl set-timezone Asia/Shanghai # 设置时区
timedatectl status # 查看时间同步状态
useradd / usermod - 用户管理
useradd username # 添加用户
usermod -aG group username # 将用户添加到组
passwd - 更改用户密码
passwd username
groupadd / groupmod - 组管理
groupadd groupname
groupmod -n newgroupname groupname
crontab - 定时任务管理
crontab -e # 编辑当前用户的定时任务
ssh - 安全外壳协议(SSH)
ssh user@host # 连接到远程主机
这些命令是CentOS系统管理和日常操作中非常常用的。当然,CentOS还有许多其他命令和工具,具体使用可以根据实际需求进行查询和学习。