当前位置: 首页 > news >正文

入门Linux简单操作

基本命令

  1. scp ✓ scp -r 文件 127.0.0.1:/root/文件 (source->>>>destination)

  2. mv cp ✓ cp xxxx ./xxxx

  3. date ✓ 修改时间 date -s “yyyy-MM-dd 12:12:59”

  4. find ✓ find /home/user -name “*.txt”

  5. grep ✓

  6. 管道

  7. 软连接

  8. 多用户

  9. 免密设置

  10. 脚本 ✓

  11. 修改权限 sudo chmod u+r /var/spool/mail/root u user用户

  12. ping 与telnet telnet 192.168.0.1 23(端口为23的服务 telnet是一种远程登录协议,通过TCP/IP网络提供了一种可靠的终端到终端的数据传输方式)

  13. top 进入后按输入命令暂停跳动

常用命令:

  1. vim 模式删除清空 1,$d

  2. 创建多层文件夹 mkdir -p dir1/dir2/dir3

  3. chmod +x script.sh (x执行 w写 r读)

  4. 脚本

    #!/bin/bash
    echo "这是一个脚本"
    
  5. 设置定时任务 cron表达式五位数(从分钟开始,周结束) crontab -e

    (定时删除0 1 * * * sudo rm /path/to/directory/old_file.txt)

  6. 查看进程号 ps aux | grep java 查看端口号 lsof i:端口号

  7. 脚本 杀掉 tomcat 进程并重新启动

  8. 查看内存 df -h

实践

1.文件是否
#!/bin/bash  # 检查文件是否存在   -f 是文件  -d是文件夹
if [ -f "test.txt" ]; then      # 删除文件  rm test.txt  echo "文件 test.txt 已删除"  
else  echo "文件 test.txt 不存在"  
fi
2.ping IP列表
input_file="ip_list.txt"
output_file="log.txt"while IFS= read -r ip;doecho "$ip"  if ! ping -c 4 "$ip" &>/dev/null;thenecho "$ip" >> "$output_file"echo "失败"elseecho "成功"fi
done < "$input_file"
3.杀进程重启
#!/bin/bash  # 查找 Tomcat 进程的进程号  
pid=$(ps aux | grep tomcat | grep -v grep | awk '{print $2}')  # 杀死 Tomcat 进程  
kill -9 $pid  # 等待一段时间,确保 Tomcat 进程已经停止  
sleep 10  # 启动 Tomcat  
/path/to/tomcat/bin/startup.sh
chmod +x restart_tomcat.sh  
./restart_tomcat.sh
http://www.lryc.cn/news/279910.html

相关文章:

  • 操作系统复习 一、二章
  • 【国内访问github不稳定】可以尝试fastgithub解决这个问题
  • android:clickable=“false“无效,依然能被点击
  • Springboot WebFlux项目结合mongodb进行crud
  • 超维空间M1无人机使用说明书——61、ROS无人机物体识别与精准投放
  • Flask 小程序菜品搜索
  • Excel·VBA按指定顺序排序函数
  • 数据结构学习笔记——查找算法中的树形查找(红黑树)
  • Debezium发布历史66
  • Redis系列之使用Lua脚本
  • Wargames与bash知识16
  • 关于运维·关于数据库面试题
  • MySQL题目示例
  • HTML基本语法
  • 二分图最大匹配——匈牙利算法详解
  • 【AI视野·今日Robot 机器人论文速览 第七十一期】Fri, 5 Jan 2024
  • xtu oj 1334 Least Common Multiple
  • 【论文笔记】End-to-End Diffusion Latent Optimization Improves Classifier Guidance
  • 【HarmonyOS4.0】第四篇-ArkUI基础实战
  • 每日一题——LeetCode1128.等价多米诺骨牌对的数量
  • 关联规则分析(Apriori算法2
  • 数据仓库(2)-认识数仓
  • C#编程-实现委托
  • Ubuntu18.04 Qt 实现MQTT
  • 【软件测试】学习笔记-不同视角的软件性能与性能指标
  • Spring MVC组件
  • vue文件在<template>中使用多个<el-main>报错(已解决)
  • 【PlantUML】- 时序图
  • openai自定义API操作 API (openai.custom):OpenAI API 实现电商平台的智能库存管理
  • 宠物服务新篇章:预约小程序带来的变革