在 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 命令行操作的基礎。隨著你對系統的熟悉,你會遇到更多高級命令和工具。記得在使用這些命令時,始終小心謹慎,特別是涉及到刪除文件或更改系統配置的操作。