Linux命令速查指南
2025年09月13日
默认分类
1039字

一、系统信息与管理

  • 查看系统信息

    My terminal window
    uname -a
  • 查看主机名

    My terminal window
    hostname
  • 查看系统运行时间

    My terminal window
    uptime
  • 查看登录用户

    My terminal window
    who
  • 查看系统进程和资源占用

    My terminal window
    top
  • 更友好的进程查看(需安装)

    My terminal window
    htop
  • 查看磁盘空间使用情况

    My terminal window
    df -h
  • 查看目录大小

    My terminal window
    du -sh /var/log
  • 查看内存使用情况

    My terminal window
    free -h

二、文件与目录操作

  • 列出当前目录文件

    My terminal window
    ls -al
  • 切换目录

    My terminal window
    cd /home
  • 显示当前路径

    My terminal window
    pwd
  • 创建目录

    My terminal window
    mkdir myfolder
  • 删除空目录

    My terminal window
    rmdir myfolder
  • 删除目录及其内容

    My terminal window
    rm -r myfolder
  • 复制文件或目录

    My terminal window
    cp file.txt /tmp/
  • 移动或重命名

    My terminal window
    mv file.txt /tmp/
  • 创建空文件

    My terminal window
    touch newfile.txt
  • 查看文件内容

    My terminal window
    cat file.txt
  • 分页查看文件

    My terminal window
    less file.txt
  • 查看文件前 10 行

    My terminal window
    head file.txt
  • 查看文件后 10 行

    My terminal window
    tail -f /var/log/syslog

三、文件查找与文本处理

  • 查找文件

    My terminal window
    find /home -name "*.log"
  • 快速查找文件(需安装 mlocate)

    My terminal window
    locate passwd
  • 搜索文件内容

    My terminal window
    grep "error" /var/log/syslog
  • 递归搜索目录

    My terminal window
    grep -r "TODO" ./project
  • 统计行数

    My terminal window
    wc -l file.txt
  • 按分隔符提取字段

    My terminal window
    cut -d ":" -f1 /etc/passwd
  • 排序

    My terminal window
    sort names.txt
  • 去重

    My terminal window
    uniq names.txt
  • 文本处理

    My terminal window
    awk '{print $1}' file.txt
  • 文本替换

    My terminal window
    sed 's/error/warn/g' file.txt

四、用户与权限管理

  • 显示当前用户

    My terminal window
    whoami
  • 查看用户 ID 和组信息

    My terminal window
    id
  • 提升权限执行命令

    My terminal window
    sudo apt update
  • 修改文件权限

    My terminal window
    chmod 755 script.sh
  • 修改文件所有者

    My terminal window
    chown root:root file.txt
  • 修改用户密码

    My terminal window
    passwd
  • 添加新用户

    My terminal window
    sudo useradd yang
  • 添加用户到组

    My terminal window
    sudo usermod -aG sudo yang

五、软件包管理(以 Debian/Ubuntu 为例)

  • 更新软件包索引

    My terminal window
    sudo apt update
  • 升级已安装软件

    My terminal window
    sudo apt upgrade
  • 安装软件包

    My terminal window
    sudo apt install git
  • 卸载软件包

    My terminal window
    sudo apt remove git
  • 搜索软件包

    My terminal window
    apt search nginx
  • 列出已安装的软件

    My terminal window
    dpkg -l

六、网络管理

  • 测试网络连通性

    My terminal window
    ping google.com
  • 查看网络接口信息(需安装 net-tools)

    My terminal window
    ifconfig
  • 查看网络接口信息

    My terminal window
    ip addr
  • 查看端口占用

    My terminal window
    netstat -tuln
    My terminal window
    ss -tuln
  • 测试 HTTP 请求

    My terminal window
    curl https://example.com
  • 下载文件

    My terminal window
    wget https://example.com/file.zip

七、进程管理

  • 查看所有进程

    My terminal window
    ps aux
  • 终止进程

    My terminal window
    kill 1234
  • 强制终止进程

    My terminal window
    kill -9 1234
  • 按名称终止进程

    My terminal window
    pkill nginx
  • 查看后台任务

    My terminal window
    jobs
  • 将任务放到后台运行

    My terminal window
    bg %1
  • 将任务放到前台运行

    My terminal window
    fg %1

八、压缩与解压

  • 打包目录

    My terminal window
    tar -cvf backup.tar /home/user
  • 解包

    My terminal window
    tar -xvf backup.tar
  • 压缩成 tar.gz

    My terminal window
    tar -czvf backup.tar.gz /home/user
  • 解压 tar.gz

    My terminal window
    tar -xzvf backup.tar.gz
  • 压缩成 zip

    My terminal window
    zip backup.zip *.txt
  • 解压 zip

    My terminal window
    unzip backup.zip

九、常用技巧

  • 查看最近执行的命令

    My terminal window
    history
  • 清屏

    My terminal window
    clear
  • 重复上一次命令

    My terminal window
    !!
  • 列出别名

    My terminal window
    alias
  • 创建别名

    My terminal window
    alias ll='ls -alF'
# Linux
作者信息:摸鱼大王.
发表于:2025年09月13日