Skip to content

Linux 指令

  1. history

    shell
    history

    查看所有历史指令。可以使用 history | grep "command" 使用 grep 来搜索特定的命令。

  2. sudo lsof | grep /tmp/zabbix_client

    shell
    sudo lsof | grep /tmp/zabbix_client

    查看文件是由哪个进程创建的。

  3. lsof -i:7003

    shell
    lsof -i:7003

    根据端口查看程序进程。

  4. ps -ef | grep 1619

    shell
    ps -ef | grep 1619

    根据进程 ID (PID) 查询程序运行情况、端口等。

  5. ps -aux | grep -v grep | grep 30671

    shell
    ps -aux | grep -v grep | grep 30671

    查看进程的 PID 文件位置。

  6. lsof -i :port_number

    shell
    lsof -i :port_number

    端口查看,系统中打开的文件和进程。

  7. kill -9 PID

    shell
    kill -9 PID

    杀掉指定 PID 的进程。

  8. crontab -l

    shell
    crontab -l

    查看系统定时任务。

  9. crontab -e

    shell
    crontab -e

    编辑系统定时任务。

  10. find / -name 搜索的名称

    shell
    find / -name 搜索的名称

    根据文件名全盘搜索。

  11. pwd

    shell
    pwd

    查询当前路径。

  12. vim 文件名

    shell
    vim 文件名

    使用 Vim 查看文件。

  13. cd /路径

    shell
    cd /路径

    直接跳到指定目录。

  14. ssh user@hostname

    shell
    ssh user@hostname

    使用 SSH 连接远程服务器。

  15. exit

    shell
    exit

    退出当前 SSH 会话。

  16. mkdir 目录名

    shell
    mkdir 目录名

    创建一个目录。

  17. rm -f 文件名

    shell
    rm -f 文件名

    删除一个文件。

  18. rm -rf 目录名

    shell
    rm -rf 目录名

    删除一个目录及其内容。

  19. mv 旧文件名 新文件名

    shell
    mv 旧文件名 新文件名

    修改文件名或将文件移动到其他位置。

  20. chmod 权限 文件名

    shell
    chmod 权限 文件名

    修改文件或目录的权限。

  21. tar -zcvf 压缩的文件名.tgz 被打包的文件路径

    shell
    tar -zcvf 压缩的文件名.tgz 被打包的文件路径

    压缩文件。

  22. tar -zxvf 压缩包 解压出的文件名

    shell
    tar -zxvf 压缩包 解压出的文件名

    解压文件。

  23. grep 关键字 文件名

    shell
    grep 关键字 文件名

    在文件中搜索指定的关键字。

  24. shutdown 一分钟后关机,并广播消息

    shell
    shutdown -h +1 "系统将在1分钟后关机,请保存工作。"
  25. shutdown -h now 立刻关机

    shell
    shutdown -h now
  26. shutdown -r now 立刻重启

    shell
    shutdown -r now
  27. shutdown -h 小时:分钟 xx时间后关机

    shell
    shutdown -h 23:00 "系统将在23:00关机。"
  28. shutdown -c 取消关机任务

    shell
    shutdown -c
  29. shutdown -k 发送关机警告

    shell
    shutdown -k "系统即将关机,请保存工作。"
  30. 下载文件(输出重定向到文件):

    shell
    curl -o output.tar.gz https://xxx.com
  31. 解压gz压缩包:

    shell
    tar -xzvf output.tar.gz
  32. 查看运行内存:

    shell
    free -h
  33. 移动文件夹保留 files 目录:

    shell
    mv 当前文件路径 移动到的路径
  34. 压缩文件成ZIP:

    shell
    zip -r mydata.zip mydata

以下是使用 scp 命令在不同服务器之间传输文件的优化示例:

35. 使用 SCP 在服务器之间传输文件

scp(安全复制)命令用于在两台计算机之间安全地传输文件。

1. 从远程服务器传输文件到本地

将远程服务器上的文件或目录传输到本地计算机。

shell
scp root@192.168.0.112:/home/remote_directory/ /home/local_user/

参数说明:

  • root@192.168.0.112:远程服务器的用户名和 IP 地址。
  • /home/remote_directory/:远程服务器上要传输的文件或目录路径。
  • /home/local_user/:本地目标目录路径。

示例

shell
scp root@192.168.0.112:/home/dell_backy/下载/user_file.zip /home/local_user/

2. 从本地传输文件到远程服务器

将本地计算机上的文件或目录传输到远程服务器。

shell
scp /home/local.zip root@192.168.0.112:/home/remote_directory/

参数说明:

  • /home/local.zip:本地文件或目录路径。
  • root@192.168.0.112:远程服务器的用户名和 IP 地址。
  • /home/remote_directory/:远程服务器上的目标目录路径。

示例

shell
scp /home/data/local_file.zip root@192.168.0.112:/home/dell_backy/上传/