Linux是一款强大的开源操作系统,广泛应用于服务器和个人计算机。熟练掌握Linux系统的常用命令是成为一名高效开发人员或系统管理员的关键。本文将整合介绍Linux系统的常用命令,涵盖文件与目录管理、文件内容查看、文件搜索与查找、文件权限与所有者管理、系统信息查看、进程管理、网络管理、系统服务管理、压缩与解压、网络通信、用户管理、系统管理与维护等方面。


二、文件与目录管理命令

1、ls: 列出目录内容。
运行命令:ls [options] [directory]
示例:ls -l /home/user/documents

2、cd: 切换当前工作目录。
运行命令:cd [directory]
示例:cd /var/www/html

3、mkdir: 创建新目录。
运行命令:mkdir [directory_name]
示例:mkdir new_directory

4、cp: 复制文件或目录。
运行命令:cp [options] source destination
示例:cp file.txt /path/to/destination

5、rm: 删除文件或目录。
运行命令:rm [options] file_or_directory
示例:rm file.txt (谨慎操作:rm -r directory_to_delete)

6、mv: 移动文件或目录,也可以用于重命名文件或目录。
运行命令:mv [options] source destination
示例:mv old_name.txt new_name.txt 或 mv file.txt /path/to/destination


三、文件内容查看命令

1、cat: 查看文件内容并将其输出到终端。
运行命令:cat [file]
示例:cat file.txt

2、less: 分页查看文件内容,适用于大文件。
运行命令:less [file]
示例:less large_file.log

3、head: 查看文件的前几行。
运行命令:head [options] file
示例:head -n 10 file.txt

4、tail: 查看文件的后几行。
运行命令:tail [options] file
示例:tail -n 20 file.txt


四、文件搜索与查找命令

1、find: 在指定目录中搜索文件。
运行命令:find [path] [expression]
示例:find /home/user -name "*.txt"

2、grep: 在文件中搜索指定文本。
运行命令:grep [options] "pattern" [file]
示例:grep "keyword" file.txt

3、locate: 快速定位文件。
运行命令:locate [file_name]
示例:locate myfile.txt


五、文件权限与所有者管理命令

1、chmod: 修改文件或目录的权限。
运行命令:chmod [options] permissions file_or_directory
示例:chmod 755 file.txt

2、chown: 更改文件或目录的所有者。
运行命令:chown [options] user:group file_or_directory
示例:chown john:users file.txt


六、系统信息查看命令

1、uname: 显示系统信息。
运行命令:uname [options]
示例:uname -a

2、df: 显示文件系统磁盘空间使用情况。
运行命令:df [options]
示例:df -h

3、free: 显示内存使用情况。
运行命令:free [options]
示例:free -h

4、top: 实时显示系统中运行的进程及其资源占用情况。
运行命令:top
示例:top


七、进程管理命令

1、ps: 显示当前用户的进程状态。
运行命令:ps [options]
示例:ps aux

2、top: 实时显示系统中运行的进程及其资源占用情况。
运行命令:top
示例:top

3、kill: 终止进程。
运行命令:kill [options] PID
示例:kill 1234


八、网络管理命令

1、ping: 检测与目标主机之间的连通性。
运行命令:ping [options] host
示例:ping google.com

2、ifconfig(或ip命令,根据不同系统而定): 显示网络接口信息。
运行命令:ifconfig
示例:ifconfig

3、netstat: 显示网络状态信息。
运行命令:netstat [options]
示例:netstat -tuln


九、系统服务管理命令

1、systemctl: 管理系统服务(适用于systemd系统)。
运行命令:systemctl [action] service_name
示例:systemctl start apache2

2、service: 管理系统服务(适用于init系统)。
运行命令:service [service_name] [action]
示例:service apache2 restart


十、系统管理与维护命令

1、shutdown: 关闭或重启系统。
运行命令:sudo shutdown -h now # 立即关闭系统

     sudo shutdown -r now  # 立即重启系统

2、reboot: 重启系统。
运行命令:sudo reboot


本文整合了Linux系统的常用命令,涵盖了文件与目录管理、文件内容查看、文件搜索与查找、文件权限与所有者管理、系统信息查看、进程管理、网络管理、系统服务管理、压缩与解压、网络通信、用户管理以及系统管理与维护等多个方面。这些命令是Linux用户和管理员必须掌握的基本工具,熟练掌握这些命令将提高工作效率,帮助您更好地管理和操作Linux系统。