3 posts tagged with "linux"

View All Tags

CPU & Memory Monitoring 101: How to Check, Analyze, and Optimize System Performance on Linux, Windows, and macOS

System performance matters—whether you're running a heavy-duty backend server on Linux, multitasking on Windows, or pushing Xcode to its limits on macOS. You don’t want your laptop sounding like a jet engine or your EC2 instance crashing from an out-of-memory error.

This guide walks you through how to check and analyze CPU and memory usage, interpret the data, and take practical actions across Linux, Windows, and macOS. Let’s dive in.


Linux: Your Terminal Is Your Best Friend#

Illustration of a person monitoring system performance on multiple computer screens representing Linux terminal usage

Check CPU and Memory Usage#

Linux gives you surgical control via CLI tools. Start with:

  • top or htop: Real-time usage metrics

    top
    sudo apt install htop
    htop
  • ps aux --sort=-%mem: Sorts by memory usage

    ps aux --sort=-%mem | head -n 10
  • free -h: View memory in a human-readable format

    free -h
  • vmstat: Shows memory, swap, and CPU context switching

    vmstat 1 5

Learn more: Linux Memory Explained

Optimization Tips#

  • Enable swap (if disabled) – Many VMs (like EC2) don’t enable swap by default:

    sudo fallocate -l 4G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
  • Tune Java apps (JVM-based) — Limit memory usage:

    -Xmx512M -Xms512M

Windows: Task Manager and Beyond#

Illustration of a person using a laptop in a workspace symbolizing system monitoring on Windows

Check Resource Usage#

  • Task Manager (Ctrl + Shift + Esc):

    • View CPU usage per core
    • Check memory consumption
    • Review app/resource breakdowns
  • Resource Monitor:

    • From Task Manager > Performance > Open Resource Monitor
    • Monitor by process, network, disk, and more
  • PowerShell:

    Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
    Get-Process | Sort-Object WS -Descending | Select-Object -First 10

Learn more: Windows Performance Tuning

Optimization Tips#

  • Disable startup apps — Uncheck unnecessary ones in the Startup tab
  • Enable paging file (virtual memory)
  • Remove bloatware — Pre-installed apps often hog memory

macOS: Spotlight with Muscle#

Illustration of a person standing beside a large laptop showing gears, representing performance monitoring on macOS

Check Resource Usage#

  • Activity Monitor:

    • Open via Spotlight (Cmd + Space > “Activity Monitor”)
    • Tabs: CPU, Memory, Energy, Disk, Network
  • Terminal Tools:

    top
    vm_stat
    • Get free memory in MB:
      pagesize=$(pagesize)
      vm_stat | awk -v page_size=$pagesize '/Pages free/ {print $3 * page_size / 1024 / 1024 " MB"}'
  • ps + sort:

    ps aux | sort -nrk 3 | head -n 10 # Top CPU
    ps aux | sort -nrk 4 | head -n 10 # Top Memory

Learn more: Apple Developer Performance Tips

Optimization Tips#

  • Close idle Chrome tabs — Each one is a separate process
  • Purge caches (dev use only):
    sudo purge
  • Reindex Spotlight (if mds is hogging CPU):
    sudo mdutil -E /

Key Metrics to Watch (Across OSes)#

MetricWhat It Tells You
%CPUProcessor usage per task/core
RSS (Memory)Actual RAM used by a process
Swap UsedMemory overflow – indicates stress
Load AverageAverage system load (Linux)
Memory PressureRAM strain (macOS)

Bonus Tools (Cross-Platform)#


TL;DR - Fixes in a Flash#

SymptomQuick Fix
High memory, no swapEnable swap (Linux) / Check paging (Win)
JVM app using too much RAMLimit heap: -Xmx512M
Chrome eating RAMClose tabs, use Safari (macOS)
Random CPU spikes (Mac)Reindex Spotlight
Background process bloatUse ps, top, or Task Manager

Final Thoughts#

System performance isn’t just about uptime — it’s about user experience, developer productivity, and infrastructure cost. The key is to observe patterns, know what “normal” looks like, and take action before things go south.

Whether you're debugging a dev laptop or running a multi-node Kubernetes cluster, these tools and tips will help you stay fast and lean.

Nife.io makes multi-cloud infrastructure and application orchestration simple. It provides enterprises with a unified platform to automate, scale, and manage workloads effortlessly.

Discover how Nife streamlines Application Lifecycle Management.

How to Delete Specific Lines from a File Using Line Numbers

When you're working with text files—be it config files, logs, or source code—you may need to delete specific lines based on their line numbers. This might sound intimidating, but it’s actually quite easy once you know which tool to use.

In this post, we’ll walk through several methods to remove lines using line numbers, using command-line tools like sed, awk, and even Python. Whether you're a beginner or a seasoned developer, there’s a solution here for you.


The Basic Idea#


To delete a specific range of lines from a file:

  1. Identify the start line and end line.
  2. Use a tool or script to remove the lines between those numbers.
  3. Save the changes back to the original file.

Let’s break this down by method.


1. Using sed (Stream Editor)#


sed is a command-line utility that’s perfect for modifying files line-by-line.

Basic Syntax#

sed 'START_LINE,END_LINEd' filename > temp_file && mv temp_file filename
  • Replace START_LINE and END_LINE with actual numbers.
  • d tells sed to delete those lines.

Example#

To delete lines 10 through 20:

sed '10,20d' myfile.txt > temp_file && mv temp_file myfile.txt

With Variables#

START_LINE=10
END_LINE=20
sed "${START_LINE},${END_LINE}d" myfile.txt > temp_file && mv temp_file myfile.txt

📚 More on sed line deletion


2. Using awk#

awk is a pattern scanning tool. It’s ideal for skipping specific lines.

Syntax#

awk 'NR < START_LINE || NR > END_LINE' filename > temp_file && mv temp_file filename

Example#

awk 'NR < 10 || NR > 20' myfile.txt > temp_file && mv temp_file myfile.txt

This prints all lines except lines 10 through 20.

📚 Learn more about awk


3. Using head and tail#

Perfect when you only need to chop lines off the start or end.

Example#

Delete lines 10 to 20:

head -n 9 myfile.txt > temp_file
tail -n +21 myfile.txt >> temp_file
mv temp_file myfile.txt
  • head -n 9 gets lines before line 10.
  • tail -n +21 grabs everything from line 21 onward.

📚 tail command explained


4. Using perl#

perl is great for more advanced file manipulation.

Syntax#

perl -ne 'print unless $. >= START_LINE && $. <= END_LINE' filename > temp_file && mv temp_file filename

Example#

perl -ne 'print unless $. >= 10 && $. <= 20' myfile.txt > temp_file && mv temp_file myfile.txt
  • $. is the line number variable in perl.

📚 Perl I/O Line Numbering


5. Using Python#

For full control or if you’re already using Python in your workflow:

Example#

start_line = 10
end_line = 20
with open("myfile.txt", "r") as file:
lines = file.readlines()
with open("myfile.txt", "w") as file:
for i, line in enumerate(lines):
if i < start_line - 1 or i > end_line - 1:
file.write(line)

Python is especially useful if you need to add logic or conditions around what gets deleted.

📚 Working with files in Python


Conclusion#


There are plenty of ways to delete lines from a file based on line numbers:

  • Use sed for simple, fast command-line editing.
  • Choose awk for conditional line selection.
  • Go with head/tail for edge-case trimming.
  • Try perl if you’re comfortable with regex and quick one-liners.
  • Opt for Python when you need logic-heavy, readable scripts.

Explore Nife.io for modern cloud infrastructure solutions, or check out OIKOS to see how edge orchestration is done right.


How to Resolve "Permission Denied" Issues When SFTP File Uploading to a Bitnami Server

Access Denied warning with a locked padlock, error symbols, and malware icons—representing SFTP permission issues on a Bitnami server.

You're not alone if you've ever attempted to upload a file to your Bitnami server using SFTP and run into the dreaded Permission denied error. When the person you're connecting as lacks the required write rights for the target directory, this problem frequently occurs. To help you troubleshoot and resolve this issue so you may resume your job, here is a simple instruction.

Recognizing the Issue#

Usually, the error looks something like this:

/path/to/target/directory/yourfile.ext" is the remote open function. Denied permission

This occurs because your SFTP account lacks write permissions to the directory you're attempting to upload to, which is held by a user (or group). This is particularly typical for WordPress or other application-related folders on Bitnami servers.

First step: Verify Permissions#

Illustration of a person entering an OTP code for two-factor authentication, representing secure login verification with a shield icon for data protection.

Go to the target directory first by SSHing into your server. To check its permissions, use the ls -ld command:

ssh -i LightsailDefaultKey.pem bitnami@yourserver
ls -ld /path/to/your/directory

This is what you'll see:

drwxr-xr-x 2 root root 4096 Nov 9 12:00 ai1wm-backups

In this instance, root is the owner of the directory, and only the owner is able to write. Your upload failed because of this.

Learn more about Linux file permissions

Second Step: Modify Permissions Temporarily#

You can let anyone write to the directory if you don't mind temporarily lowering the directory permissions:

sudo chmod 777 /path/to/your/directory

Next, use SFTP to upload your file:

sftp -i LightsailDefaultKey.pem bitnami@yourserver
cd /path/to/your/directory
put yourfile.ext

Revert the permissions to a more secure level after the upload is finished:

sudo chmod 755 /path/to/your/directory

More details on chmod

Step 3: Use scp with sudo#

Illustration of a person sitting with a laptop in front of a large screen showing a software update in progress, with cloud upload and refresh icons representing system updates and synchronization.

Another choice if you don't want to change the directory permissions is to upload the file to a temporary directory, such as /tmp, using scp (secure copy), and then use sudo to move it to the target directory.

Transfer the file to /tmp:#

scp -i LightsailDefaultKey.pem yourfile.ext bitnami@yourserver:/tmp

Move the file to the target directory:#

ssh -i LightsailDefaultKey.pem bitnami@yourserver
sudo mv /tmp/yourfile.ext /path/to/your/directory/

Best Practices#

  • Use the Least Privileges Required: To avoid security issues, always reverse directory permissions after finishing an operation.

  • Verify Control: If this is a routine task, think about giving the Bitnami user control of the directory:

    sudo chown bitnami:bitnami /path/to/your/directory
  • Automate Using Scripts: If you frequently perform this task, a straightforward script can help you save time and effort.

Bitnami Documentation has additional guidance on managing permissions effectively.

Conclusion#

That's it! You may easily upload your files and get around the Permission denied problem by changing permissions or by utilizing scp with sudo. This technique is applicable to any Linux-based system with comparable permission problems, not just Bitnami servers.

If you're looking for cloud deployment, check out what Oikos by Nife has to offer.