CentOS 6.3 命令速查手册

文件系统操作
查看文件系统类型
file /path/to/file
创建文件
touch /path/to/file
复制文件
cp source_path destination_path
移动文件
mv source_path destination_path
删除文件
rm -f /path/to/file
-
cat /path/to/file
分页查看文件内容
less /path/to/file
查看文件权限
ls -l /path/to/file
修改文件权限
chmod 755 /path/to/file
查看文件大小
du -sh /path/to/file
目录操作
创建目录
mkdir /path/to/directory
切换目录
cd /path/to/directory
-
ls /path/to/directory
创建多级目录
mkdir -p /path/to/directory1/directory2
删除目录

rm -rf /path/to/directory
改变目录名称
mv /path/to/old_directory /path/to/new_directory
压缩和解压
压缩文件
tar -czvf filename.tar.gz /path/to/directory
解压文件
tar -xzvf filename.tar.gz -C /path/to/directory
压缩并解压
tar -czvf filename.tar.gz /path/to/directory && tar -xzvf filename.tar.gz -C /path/to/directory
文件查找
查找文件
find /path/to/directory -name "filename"
查找文件并打印路径
find /path/to/directory -print -name "filename"
查找包含特定字符串的文件
grep "string" /path/to/directory
文本处理
查看文本文件内容
cat /path/to/file
分页查看文本文件内容
less /path/to/file
查找文本文件中的内容
grep "string" /path/to/file
替换文本文件中的内容
sed -i 's/old_string/new_string/g' /path/to/file
系统信息

查看CPU信息
cat /proc/cpuinfo
查看内存信息
free -m
查看磁盘信息
df -h
查看系统版本
cat /etc/redhat-release
查看系统时间
date
用户和组操作
添加用户
useradd username
删除用户
userdel username
添加用户到组
usermod -aG groupname username
删除用户从组
gpasswd -d username groupname
查看用户信息
id username
FAQs:
Q1: 如何查看当前用户名? A1: 使用 whoami 命令可以查看当前用户名。
Q2: 如何修改用户密码? A2: 使用 passwd 命令可以修改用户密码,修改用户 username 的密码,可以使用 passwd username 命令。

