在 Linux 系统中,有众多强大的命令可以帮助用户进行系统管理、文件操作、进程控制等各种任务。以下是对常见的 Linux 命令进行全面汇总,同时介绍一些常见目录。
一、常见目录介绍
- /root:Superuser's home directory.(超级用户 root 的主目录)。
- /home:Home directories for regular users.(普通用户的主目录存放位置,每个用户在/home 下有一个以用户名命名的子目录)。
- /bin:Contains common executable programs.(存放常用的二进制可执行文件,如 ls、cat、cp 等命令)。
- /sbin:Stores system administration programs.(存放系统管理相关的二进制可执行文件,通常只有管理员可以执行)。
- /etc:Holds system configuration files.(存放系统配置文件,如网络配置、用户账号密码等)。
- /usr:Contains many application programs and files for users.(包含用户的许多应用程序和文件,如/usr/bin 和/usr/sbin 分别存放用户级的命令和系统管理命令)。
- /var:Stores data that changes frequently.(存放经常变化的数据,如日志文件、邮件队列等)。
- /tmp:Temporary file directory.(临时文件存放目录,系统重启时会清空该目录)。
二、文件和目录操作命令
ls (list)
- 作用:Lists directory contents.(列出目录内容)。
- 示例: ls lists files and subdirectories in the current directory. ls -l shows detailed information in long format, including file permissions, owner, size, and modification time.( ls 列出当前目录下的文件和子目录, ls -l 以长格式显示详细信息,包括文件权限、所有者、大小和修改时间等)。
cd (change directory)
- 作用:Changes the current directory.(切换目录)。
- 示例: cd /home/user switches to the /home/user directory.( cd /home/user 切换到/home/user 目录)。
pwd (print working directory)
- 作用:Displays the path of the current working directory.(显示当前工作目录的路径)。
mkdir (make directory)
- 作用:Creates a new directory.(创建新目录)。
- 示例: mkdir newdir creates a directory named newdir.( mkdir newdir 创建名为 newdir 的目录)。
rmdir (remove directory)
- 作用:Removes an empty directory.(删除空目录)。
rm (remove)
- 作用:Deletes files or directories.(删除文件或目录)。
- 示例: rm file.txt deletes file.txt. rm -r dir deletes directory dir and its contents.( rm file.txt 删除文件 file.txt, rm -r dir 删除目录 dir 及其内容)。
cp (copy)
- 作用:Copies files or directories.(复制文件或目录)。
- 示例: cp file1.txt file2.txt copies file1.txt to file2.txt. cp -r dir1 dir2 copies directory dir1 to dir2.( cp file1.txt file2.txt 复制 file1.txt 为 file2.txt, cp -r dir1 dir2 复制目录 dir1 到 dir2)。
mv (move)
- 作用:Moves files or directories and can also be used to rename files or directories.(移动文件或目录,也可用于重命名文件或目录)。
- 示例: mv file1.txt /home/user moves file1.txt to the /home/user directory. mv oldname.txt newname.txt renames a file.( mv file1.txt /home/user 将 file1.txt 移动到/home/user 目录, mv oldname.txt newname.txt 重命名文件)。
touch
- 作用:Creates a new empty file or updates the timestamp of a file.(创建一个新的空文件或更新文件的时间戳)。
cat (concatenate)
- 作用:Views file contents.(查看文件内容)。
- 示例: cat file.txt shows the contents of file.txt.( cat file.txt 显示 file.txt 的内容)。
more/less
- 作用:Displays file contents page by page.(分页查看文件内容)。
head/tail
- 作用:Respectively shows the beginning and end parts of a file.(分别显示文件的开头和结尾部分内容)。
三、文件权限管理命令
chmod (change mode)
- 作用:Changes file or directory permissions.(改变文件或目录的权限)。
- 示例: chmod u+rwx file.txt adds read, write, and execute permissions for the owner of the file. chmod 755 dir sets the permissions of a directory to read, write, and execute for the owner, and read and execute for group users and others.( chmod u+rwx file.txt 为文件的所有者添加读、写、执行权限, chmod 755 dir 将目录的权限设置为所有者有读、写、执行权限,组用户和其他用户有读和执行权限)。
chown (change owner)
- 作用:Changes the owner of a file or directory.(改变文件或目录的所有者)。
- 示例: chown user:group file.txt changes the owner of the file to user and the group to group.( chown user:group file.txt 将文件的所有者改为 user,所属组改为 group)。
四、系统信息查看命令
uname (Unix name)
- 作用:Displays system information.(显示系统信息)。
- 示例: uname -a shows all system information, including kernel name, hostname, kernel version, etc.( uname -a 显示系统的所有信息,包括内核名称、主机名、内核版本等)。
top
- 作用:Dynamically displays information about running processes, including CPU and memory usage.(动态显示系统中正在运行的进程信息,包括 CPU 和内存使用情况等)。
free
- 作用:Displays memory usage.(显示系统内存使用情况)。
df (disk free)
- 作用:Displays disk space usage.(显示磁盘空间使用情况)。
du (disk usage)
- 作用:Displays the disk space occupied by files or directories.(显示文件或目录占用的磁盘空间大小)。
五、进程管理命令
ps (process status)
- 作用:Displays information about current system processes.(显示当前系统中的进程信息)。
- 示例: ps aux shows detailed information about all processes for all users.( ps aux 显示所有用户的所有进程详细信息)。
kill
- 作用:Terminates a process.(终止进程)。
- 示例: kill -9 pid forcefully terminates the process with process ID pid.( kill -9 pid 强制终止进程 ID 为 pid 的进程)。
top
- 作用:Dynamically displays information about running processes and can be used for real-time monitoring of process status.(动态显示系统中正在运行的进程信息,可用于实时监控进程状态)。
六、网络相关命令
ifconfig (interface configuration)
- 作用:Displays or configures network interface information.(显示或配置网络接口信息)。
ping (Packet Internet Groper)
- 作用:Tests network connectivity.(测试网络连接)。
- 示例: ping www.example.com tests network connectivity to a website.( ping www.example.com 测试与网站的网络连接)。
telnet/ssh
- 作用:Allows remote login to other hosts.(远程登录到其他主机)。
七、压缩和解压缩命令
tar (tape archive)
- 作用:Packages and compresses files.(打包和压缩文件)。
- 示例: tar -cvf archive.tar file1.txt file2.txt creates an archive named archive.tar containing file1.txt and file2.txt. tar -xvf archive.tar extracts the contents of archive.tar.( tar -cvf archive.tar file1.txt file2.txt 创建一个名为 archive.tar 的包,包含 file1.txt 和 file2.txt, tar -xvf archive.tar 解包 archive.tar)。
gzip/gunzip
- 作用:Compresses and decompresses files.(压缩和解压缩文件)。
- 示例: gzip file.txt compresses file.txt to file.txt.gz. gunzip file.txt.gz decompresses file.txt.gz.( gzip file.txt 压缩 file.txt 为 file.txt.gz, gunzip file.txt.gz 解压缩 file.txt.gz)。
八、系统性能监控命令
sar (System Activity Reporter)
- 作用:Monitors system activity, including CPU, memory, disk I/O, and network usage.(监控系统活动,包括 CPU、内存、磁盘 I/O 和网络使用情况)。
cron
- 作用:Allows scheduling of tasks to run at specific times.(允许在特定时间安排任务运行)。
掌握这些 Linux 命令,可以让用户更加高效地管理和使用 Linux 系统。