Skip to content

Instantly share code, notes, and snippets.

@aleksejalex
Last active March 30, 2026 18:46
Show Gist options
  • Select an option

  • Save aleksejalex/d85b321288812049868b1c3fb8cb8631 to your computer and use it in GitHub Desktop.

Select an option

Save aleksejalex/d85b321288812049868b1c3fb8cb8631 to your computer and use it in GitHub Desktop.

Linux Command Cheatsheet

version 20250715, by AG, reformatted by Google Gemini 2.5 Pro

Python Management 🐍

Commands for managing Python versions with pyenv and handling virtual environments.

Pyenv: Python Version Management

# List all available python versions
pyenv versions

# Install a specific python version
pyenv install 3.9.13

# Set a specific python version for the current directory
pyenv local 3.10.6

Note: You can use a Python version installed via pyenv as the interpreter for projects in IDEs like PyCharm.


Venv: Virtual Environments

First, ensure you've set your desired Python version using pyenv.

# Create a virtual environment in a folder named .venv
python3 -m venv .venv

# Activate the virtual environment
source .venv/bin/activate

# Deactivate the virtual environment
deactivate

Version Control & Remote Operations 🌐

Commands for Git, SSH, SCP, and running processes on remote servers.

Git: Discard Local Changes

To discard all local changes and sync with the remote repository:

# Reset local repository to the last commit (discards all local changes)
git reset --hard

# Fetch the latest changes from the remote 'origin'
git fetch origin

# Pull the changes for a specific branch
git pull origin <branch_name>

SSH & SCP: Remote Connection & File Transfer

# Connect to a remote server via SSH
ssh myname@server.institute.cz

# Copy a local file to a directory on a remote server
scp platform_info.py myname@server.institute.cz:~/working_dir

# Copy a directory from a remote server to the current local directory (-r for recursive)
scp -r myname@server.institute.cz:~/remote_dir/ ./my_local_dir

Running Processes on a Remote Server

To run a script in the background on a remote server, ensuring it continues even after you log out:

# Run a python script on CPU cores 1 and 2 in the background
nohup taskset -c 1,2 python measure_script.py &

VPN connection to server(s)

To run a script in the background on a remote server, ensuring it continues even after you log out:

sudo openconnect --servercert=<certwillbeissuedbyserveronconnectionattempt> --protocol=nc https://udun.site.cas.cz --authgroup="department" --user=username

Remote JupyterLab Access

  1. Connect to your server via SSH:
    ssh myname@server.institute.cz
  2. On the server, activate the correct environment (e.g., conda) and start JupyterLab on a specific port:
    # Example for conda
    conda activate my_custom_env
    
    # Start jupyter on port 8888, accessible from any IP on the server
    jupyter lab --no-browser --port=8888 --ip=0.0.0.0
  3. In a new local terminal window, create an SSH tunnel that forwards the server's port to your local machine:
    ssh -L 8888:localhost:8888 myname@server.institute.cz
  4. Open the JupyterLab URL (provided in the server's terminal output) in your local web browser. It will look something like http://127.0.0.1:8888/lab?token=....

Hardware & System Information πŸ’»

Commands to inspect system hardware, storage devices, and power status.

General Device Information

# Display a detailed tree of all hardware (device manager alternative)
sudo lshw

# List all PCI devices
lspci

# List all USB devices
lsusb

Change CPU frequencies/govenor:

sudo cpupower frequency-set -g performance  # to set different governor
cpupower frequency-info  # to check info and available governors

Storage Devices (SSD/HDD)

# List all NVMe SSDs
sudo nvme list

# Get a detailed SMART log for a specific NVMe drive
sudo nvme smart-log /dev/nvmeXXX

# Show detailed info and wear for a drive using smartmontools
sudo smartctl -a /dev/nvme0n1

# Manually trigger the TRIM command on an SSD to clean unused blocks
sudo fstrim -v /

Webcam & IR Camera

Your primary camera is typically /dev/video0 and the IR camera might be /dev/video2.

# Enable the IR camera to activate when requested by an application
# Requires chicony-ir-toggle: [https://github.com/PetePriority/chicony-ir-toggle](https://github.com/PetePriority/chicony-ir-toggle)
chicony-ir-toggle -d /dev/video2 on

Keyboard: Reassign Keys

To find the keycode for a specific key press:

# Listens for key presses and prints their codes
acpi_listen

For a detailed guide, see the Gentoo Wiki on ThinkPad Special Buttons.


Power Profiles

# Check the current power profile status
powerprofilesctl

Alternatively this can be used:

sudo cpufreq-set -g performance
sudo cpufreq-set -g powersave

where -g specifies the governor on CPU (available ones can be listed by cpufreq-info)


Software & Desktop Environment πŸ–₯️

Commands for package management, desktop environment tweaks, and other utilities.

Pip: Update All Packages

# Upgrade all installed Python packages using pip
pip install --upgrade $(pip freeze | awk '{split($0, a, "=="); print a[1]}')

XFCE: Reset Panel

If the XFCE panel is broken, this command chain will reset it to its default configuration.

xfce4-panel --quit ; pkill xfconfd ; rm -rf ~/.config/xfce4/panel ; rm -rf ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml ; xfce4-panel

More details can be found on the Linux Mint Forums.


Xfce4 set keyboard shortcut to switch between keyboard layouts

setxkbmap -option grp:shift_caps_toggle

ClamAV: Terminal Antivirus

# Scan a single file
clamscan MyFile.txt

# Scan an entire directory
clamscan suspiciousdir

Pandoc: Document Converter

A powerful command-line tool for converting between formats like LaTeX, Word, Markdown, HTML, and more. See Pandoc Demos.

# Convert a LaTeX file to a .docx Word document
pandoc -s DP_AG.tex -o example2.docx

# Convert a .docx Word document to a LaTeX file
pandoc -s Layout_AG.docx -o example3.tex

QEMU/KVM: Lightweight Virtualization

A lightweight option for running virtual machines on Linux.

# Install the core QEMU system
sudo apt install qemu-system

# Install Virt-Manager, a GUI for managing QEMU/KVM virtual machines
sudo apt install virt-manager

Image manipulations

how to remove white background into transparent one (png files). Fuzz (in percentage) means how aggresive it is. You have to have ImageMagick installed via apt.

convert cctv.png -fuzz 10% -transparent white cctv_no_background.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment