新闻详情

新闻详情

首页 / 资讯中心 / 详情

Building a System Information Fetch Tool in Bash

发布时间:2026/9/27 6:57:48来源:尧图网络
Building a System Information Fetch Tool in Bash
I once needed aquick system overview—CPU load, memory usage, disk space—but opening multiple commands felt inefficient. Instead of runningtop,df -h, andfree -mseparately, I decided toautomate everything in a single Bash script.The result? Acustom system fetch toolthat provides essential system details at a glance. In this guide, youll learn how to build your ownstep by step, improving your Bash scripting skills along the way.Step 1: The Basics (What We’re Fetching)Before we jump into coding, let’s outline what information we need:✅CPU Model Load(/proc/cpuinfo,top)✅Memory Usage(free -m)✅Disk Space(df -h)✅System Uptime(uptime)✅Network Information(ip a,hostname -I)Step 2: Writing the Script (Fundamentals First)1️⃣Shebang SetupStart by specifying Bash as the interpreter and clearing the screen:#!/bin/bash clear2️⃣Fetching CPU InfoExtract theCPU model nameusinggrepon/proc/cpuinfo:cpu_model$(grep model name /proc/cpuinfo | head -1 | cut -d : -f2)Get theCPU loadusingtop(oruptimefor a lightweight alternative):cpu_load$(top -bn1 | grep load average | awk {print $10})3️⃣Checking Memory UsageUsefree -mto display RAM usage in MB:mem_usage$(free -m | awk NR2{printf Used: %sMB / Total: %sMB, $3, $2})4️⃣Fetching Disk SpaceList available disk space usingdf -h:disk_usage$(df -h | awk $NF/{printf Used: %d%%, $5})5️⃣Displaying Network InfoFetch thecurrent IP address:ip_address$(hostname -I | awk {print $1})Step 3: Formatting Output for ReadabilityInstead of printing raw text, format the output neatly usingcolors and spacing:echo -e \033[32mSystem Information:\033[0m echo ------------------------------- echo -e CPU Model: $cpu_model echo -e CPU Load: $cpu_load echo -e Memory: $mem_usage echo -e Disk Space: $disk_usage echo -e IP Address: $ip_addressWhy it’s useful:Colorsimprove readabilityConsistent spacingmakes it visually appealingStep 4: Running the ScriptSave the scriptassysfetch.shMake it executable:chmod x sysfetch.shRun it:./sysfetch.shExpected Output (Example):System Information: ------------------------------- CPU Model: Intel(R) Core(TM) i7-9750H CPU 2.60GHz CPU Load: 0.78 Memory: Used: 3800MB / Total: 16000MB Disk Space: Used: 42% IP Address: 192.168.1.10Step 5: Enhancing the Script✅Add Live UpdatesInstead of a one-time report, refresh every few seconds:while true; do clear ./sysfetch.sh sleep 5 done✅Save Output to a Log FileRedirect output for future analysis:./sysfetch.sh | tee system_report.txt✅Make It InteractiveAllow users to choose what info to display:echo Select an option: [1] CPU [2] Memory [3] Disk [4] All read choice case $choice in 1) echo CPU Model: $cpu_model ;; 2) echo Memory: $mem_usage ;; 3) echo Disk Space: $disk_usage ;; 4) ./sysfetch.sh ;; *) echo Invalid option ;; esacFinal ThoughtsCreating acustom system fetch toolis a great way to:✅Improve your Bash scripting skills✅Understand Linux system commands✅Make system monitoring more efficientIf youre abeginner, this project gives youreal-world Bash experience. If youreadvanced, you can customize it further with more data points.
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

预制AIDC产业分析:全模块化设计如何把交付周期从6个月压到100天 2026/9/27 6:57:45

预制AIDC产业分析:全模块化设计如何把交付周期从6个月压到100天

CUBE 5.0全模块化AIDC拆解:100天交付周期背后的技术架构与产业变量 如果你正在关注全模块化设计、预制AIDC、CUBE 5.0、交付周期、模块化率、风液兼容等方向,本文基于公开信息整理,可作为AIDC建设模式选型与产业判断的技术参考。 一、产业背景…

阅读更多 →
北京网页设计师工资有多少图解步骤拆解真实薪资与避坑指南 2026/9/27 6:57:39

北京网页设计师工资有多少图解步骤拆解真实薪资与避坑指南

北京网页设计师工资有多少图解步骤拆解真实薪资与避坑指南 改个需求建站公司拖一周,这种憋屈感很多甲方都懂。你以为是技术瓶颈,其实往往是流程烂尾。很多老板问“北京网页设计师工资有多少”,心里没底,怕被坑,也怕招不到人。今天不讲虚的,直接上…

阅读更多 →
gsd-core 执行阶段停滞检测与安全恢复契约:中断的 execute-phase 如何在重复派发前暴露部分计划漂移 2026/9/27 6:57:32

gsd-core 执行阶段停滞检测与安全恢复契约:中断的 execute-phase 如何在重复派发前暴露部分计划漂移

【免费下载链接】gsd-core Git. Ship. Done - Core 项目地址: https://gitcode.com/gh_mirrors/ge/gsd-core 点击查看 免费下载 本篇文章以变更记录 .changeset/archived/sturdy-rams-forage.md(type: Fixed,PR #3329)为骨架展开…

阅读更多 →
深入 isomorphic-git 的 walk API:用 TREE、WORKDIR、STAGE 构建高效的递归树遍历 2026/9/27 6:57:32

深入 isomorphic-git 的 walk API:用 TREE、WORKDIR、STAGE 构建高效的递归树遍历

开发工具 【免费下载链接】isomorphic-git A pure JavaScript implementation of git for node and browsers! 项目地址: https://gitcode.com/gh_mirrors/is/isomorphic-git 点击查看 免费下载 walk 是 isomorphic-git 中一个强大的递归树遍历工具:它允…

阅读更多 →
PaddleSeg DiceLoss 深度解析:医学影像分割中的 Dice 系数损失函数原理与配置实战 2026/9/27 6:57:32

PaddleSeg DiceLoss 深度解析:医学影像分割中的 Dice 系数损失函数原理与配置实战

人工智能计算机视觉预训练 【免费下载链接】PaddleSeg Easy-to-use image segmentation library with awesome pre-trained model zoo, supporting wide-range of practical tasks in Semantic Segmentation, Interactive Segmentation, Panoptic Segmentation, Image Matting,…

阅读更多 →
Ultimate Vocal Remover (UVR5) 快速上手:一首歌里把干声和伴奏分开,只需 4 步 2026/9/27 6:57:25

Ultimate Vocal Remover (UVR5) 快速上手:一首歌里把干声和伴奏分开,只需 4 步

Ultimate Vocal Remover (UVR5) 快速上手:一首歌里把干声和伴奏分开,只需 4 步 【免费下载链接】ultimatevocalremovergui GUI for a Vocal Remover that uses Deep Neural Networks. 项目地址: https://gitcode.com/GitHub_Trending/ul/ultimatevoca…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞 ✉