Skip to content
Home » Get the Inside Scoop on Your System Info with a Bash Script

Get the Inside Scoop on Your System Info with a Bash Script

Here is a bash script that will display system information such as the OS, disk and memory usage, CPU, and the 5 most recently modified files by users. It will also check for outdated packages and display a message if any are found:

#!/bin/bash

# Display the OS name and version
echo "Operating System: $(uname -a)"

# Display disk usage
echo "Disk usage: $(df -h)"

# Display memory usage
echo "Memory usage: $(free -m)"

# Display CPU information
echo "CPU information: $(lscpu)"

# Display the 5 most recently modified files by users
echo "Recently modified files:"
ls -ltu ~ | head -n 6

# Check for outdated packages
outdated_packages=$(apt list --upgradable 2>/dev/null | grep -v "Listing..." | wc -l)
if [ "$outdated_packages" -gt 0 ]; then
  echo "Outdated packages found: $outdated_packages"
else
  echo "No outdated packages found"
fi

To use this script, save it to a file with a .sh extension and make it executable using the chmod command. For example:

chmod +x sysinfo.sh

You can then run the script by entering the following command:

./sysinfo.sh

Output example

Here is an example of what the output of the script might look like:

Operating System: Linux myhost 4.19.0-16-generic #16-Ubuntu SMP Thu Oct 10 10:59:10 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Disk usage: Filesystem      Size  Used Avail Use% Mounted on
udev            7.7G     0  7.7G   0% /dev
tmpfs           1.6G  9.2M  1.6G   1% /run
/dev/sda1       238G   41G  191G  18% /
tmpfs           7.7G   38M  7.7G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           7.7G     0  7.7G   0% /sys/fs/cgroup
tmpfs           1.6G   60K  1.6G   1% /run/user/1000
Memory usage:              total        used        free      shared  buff/cache   available
Mem:            15951       2064       7708         75       6178      13079
Swap:             0          0          0
CPU information: Architecture:        x86_64
CPU op-mode(s):  32-bit, 64-bit
Byte Order:      Little Endian
CPU(s):          8
On-line CPU(s) list:   0-7
Thread(s) per core:    2
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 158
Model name:            Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Stepping:              9
CPU MHz:               800.000
CPU max MHz:           3800.0000
CPU min MHz:           800.0000
BogoMIPS:              5604.00
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              6144K
Recently modified files:
total 16
-rw-rw-r-- 1 user user   37 Mar  9 21:20 file5.txt
-rw-rw-r-- 1 user user   37 Mar  9 21:19 file4.txt
-rw-rw-r-- 1 user user   37 Mar  9 21:18 file3.txt
-rw-rw-r-- 1 user user   37 Mar  9 21:17 file2.txt
-rw-rw-r-- 1 user user   37 Mar  9 21:16 file1.txt
drwxrwxr-x 2 user user 4096 Mar  9 21:15 .
No outdated packages found

Note that the output may vary depending on the specific system and configuration.

Neofetch

An alternative to the bash script discussed above is the neofetch command-line utility. Neofetch is a system information tool that is easy to use and displays a wide range of system information in a visually appealing format. It is available in many Linux distributions and can be installed using the package manager. To use the neofetch command, simply enter the following command in the terminal:

The output of the command includes system information such as the OS name and version, disk usage, memory usage, CPU information, and the 5 most recently modified files by users. It also checks for outdated packages and displays a message if any are found.

Leave a Reply

Your email address will not be published. Required fields are marked *

two × five =