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.
企业数字化 ERP 产品动态
相关推荐
信息可以公开,价格必须下桌:河北工厂网“四不“黄页与B2B定价权的回归 【摘要】收录497个区县产业、14809家企业、覆盖167个区县的河北工厂网,数周涌入超18万用户。内容以刚需、伯特兰陷阱、信息不对称二次分配3层逻辑归因走红,对照1688、找钢网、国联股份、淘工厂等平台的财报级数据,给出4条变现路径、3条可验证… · 2026/9/26 4:13:08
崔巍数据库实验包:可验证ACID的双库SQL工程实践 /* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/9/26 4:13:08
ADRC控制算法原理与工程实践:从洗衣机到云台的鲁棒控制落地 1. 为什么ADRC不是“另一个PID”——从滚筒洗衣机抖动说起你拆过家里的滚筒洗衣机吗?不是看说明书,是真拆。我去年修一台甩干时疯狂晃动的机器,发现它用的不是传说中“万能”的PID控制器,而是一套标着“ADRC”的控制板。当时我就愣… · 2026/9/26 4:58:24
CH341PAR并口驱动详解:USB转并口与老设备兼容性实战指南 简介:一套围绕CH341芯片USB转并行接口的完整资料包,面向电子工程师、嵌入式爱好者及需要让老式并行设备接入现代电脑的用户。压缩包共90个文件,约6.71MB,包含CH341芯片说明书、驱动/配置程序、VC工程源码(cpp/h文件&am… · 2026/9/26 4:58:17
Windows Mobile老设备复活指南:从电池唤醒到软件部署 还记得从抽屉深处翻出一台 Windows Mobile 老机器的感觉吗?屏幕亮了一下又灭掉,插上数据线电脑毫无反应,充电指示灯像心跳一样忽明忽暗。大多数人在这一步就放弃了,但实际上,只要按正确顺序处理,十台里有八… · 2026/9/26 4:58:17
SWARD自托管知识库:用Docker Compose搭建开源笔记系统 做技术这行久了,笔记和文档一定会越积越多。我试过本地 Markdown 文件夹、在线文档、各种笔记 App,最后都卡在同一个地方:内容一多,整理和检索的成本比记录本身还高。后来我把目光放到开源自托管方向上,折腾了一圈&… · 2026/9/26 4:58:17
结构化Prompt+Paperxie,高效写出高质量文献综述 你写过文献综述吗?那种被导师一句“没有学术逻辑”打回来、重写三遍还过不了关的经历,是不是现在回想起来都心有余悸?我这些年没少帮CS本科生改毕业论文,几乎每个初稿都被批过“像目录”“没有观点”“看不出你读了多少”。后来我… · 2026/9/26 4:58:17
用memmove优化插入排序:从逐元素搬运到整块搬移的性能实战 不知道你有没有遇到过这种场景:手写一个插入排序,数据量不大不小,几千个整数,跑起来却总觉得慢;或者你维护的嵌入式代码里有个排序模块,性能怎么调都差口气。我最早也以为插入排序嘛,O(n) 的算法… · 2026/9/26 4:58:05
数据库课后习题答案别硬背:当测试用例集刷,效率翻倍 简介:万常选版《数据库原理与设计》课后习题答案资源,覆盖第2至6章及第9章,适合正在学习关系模型、数据库建模、关系数据理论与模式求精的本科生、自学者作为复习与自测材料。压缩包共7个文件,含3个doc参考答案、2个sql示例脚本、… · 2026/9/26 0:00:21
OpenClaw 替代品?Hermes Agent 踩坑实录:macOS 飞书接入 TaoToken 配置 /* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/9/26 0:00:40
向下兼容与向上兼容:接口设计中的兼容性策略与工程实践 一次版本升级事故,是很多团队绕不过去的坎。线上环境里,服务端明明已经上线了新版接口,老的移动端还在照着旧文档传参数。请求一到网关,校验直接拒绝,用户操作失败,客服群炸了锅,开发群里开始互… · 2026/9/26 0:00:46