在 CentOS 系统中,命令行界面(CLI)是一个非常强大的工具,可以用来执行各种系统管理和配置任务。以下是一些基本的 CentOS 命令行操作:
首先,你需要通过 SSH 或者直接在终端中登录到 CentOS 系统。
ssh username@hostname
或者直接打开终端并输入用户名和密码。
以下是一些常用的 CentOS 命令:
ls
- 列出目录内容ls -l /path/to/directory
cd
- 改变当前目录cd /path/to/directory
pwd
- 显示当前工作目录pwd
mkdir
- 创建新目录mkdir new_directory
rmdir
- 删除空目录rmdir directory_to_remove
rm
- 删除文件或目录rm file_to_remove
rm -r directory_to_remove
cp
- 复制文件或目录cp source_file destination_file
cp -r source_directory destination_directory
mv
- 移动或重命名文件或目录mv old_name new_name
mv file_to_move /path/to/destination
cat
- 显示文件内容cat file_to_view
more
/less
- 分页显示文件内容more file_to_view
less file_to_view
grep
- 在文件中搜索文本grep "search_text" file_to_search
find
- 查找文件find /path/to/search -name filename
chmod
- 更改文件权限chmod 755 file_to_change_permissions
chown
- 更改文件所有者chown username:groupname file_to_change_owner
top
- 显示系统进程和资源使用情况top
df
- 显示磁盘空间使用情况df -h
du
- 显示目录或文件的磁盘使用情况du -sh directory_to_check
ping
- 检查网络连接ping example.com
wget
- 下载文件wget http://example.com/file_to_download
curl
- 用于传输数据curl http://example.com
CentOS 使用 ext4 文件系统,你可以使用以下命令来管理文件系统:
mount
- 挂载文件系统mount /dev/sdb1 /mnt/mydisk
umount
- 卸载文件系统umount /mnt/mydisk
fsck
- 检查并修复文件系统fsck /dev/sdb1
你可以使用以下命令来管理用户和组:
useradd
- 添加新用户useradd new_user
usermod
- 修改用户信息usermod -aG group_name user_name
groupadd
- 添加新组groupadd new_group
passwd
- 更改用户密码passwd user_name
你可以使用以下命令来配置网络:
ifconfig
- 显示和配置网络接口ifconfig eth0 192.168.1.100 netmask 255.255.255.0
ip
- 现代的网络配置工具ip addr add 192.168.1.100/24 dev eth0
ip link set eth0 up
systemctl
- 管理 systemd 服务systemctl start httpd
systemctl stop httpd
systemctl enable httpd
systemctl disable httpd
CentOS 使用 yum
或 dnf
作为包管理器:
yum
- 安装软件包yum install package_name
yum update
- 更新软件包yum update
yum remove
- 删除软件包yum remove package_name
dnf
- Fedora 和 CentOS 8 及以上版本的包管理器dnf install package_name
dnf update
dnf remove package_name
这些只是 CentOS 命令行操作的基础。随着你对系统的熟悉,你会遇到更多高级命令和工具。记得在使用这些命令时,始终小心谨慎,特别是涉及到删除文件或更改系统配置的操作。