Geody Labs


# Main Index: Debian Linux Magic Spells Cheat Sheet (one liners, how to, tips and tricks)

# System Information

Information about the vendor:
cat /sys/class/dmi/id/sys_vendor # System Vendor

Information about the machine (virtual or physical):
cat /sys/class/dmi/id/product_name # Product Name
cat /sys/class/dmi/id/product_uuid # Product UUID
cat /sys/class/dmi/id/product_serial # Product Serial
cat /sys/class/dmi/id/product_version # Product Version (if any)

cat /sys/class/dmi/id/chassis_vendor # Chassis Vendor (if there is an enclosure)
cat /sys/class/dmi/id/chassis_type # Chassis Type
cat /sys/class/dmi/id/chassis_version # Chassis Version (if any)
cat /sys/class/dmi/id/chassis_serial # Chassis Serial (if any)
cat /sys/class/dmi/id/chassis_asset_tag # Chassis Asset Tag (if any)

cat /sys/class/dmi/id/board_vendor # Board Vendor
cat /sys/class/dmi/id/board_name # Board Name
cat /sys/class/dmi/id/board_version # Board Version (if any)
cat /sys/class/dmi/id/board_serial # Board Serial (if any)
cat /sys/class/dmi/id/board_asset_tag # Board Asset Tag (if any)

cat /sys/class/dmi/id/bios_vendor # BIOS Vendor
cat /sys/class/dmi/id/bios_version # BIOS Version
cat /sys/class/dmi/id/bios_date # BIOS Date

Show Machine's Unique ID:
cat /etc/machine-id # show the unique machine ID of the local system that is set during installation. The machine ID is a single newline-terminated, hexadecimal, 32-character, lowercase machine ID string. When decoded from hexadecimal, this corresponds with a 16-byte/128-bit string (from the manual). Also in /var/lib/dbus/machine-id

Boot ID:
cat /proc/sys/kernel/random/boot_id # show the random ID regenerated at each boot

Session ID
cat /proc/self/sessionid # show the session ID, which is unique for each login

Show Boot parameters for last (current) boot:
cat /proc/cmdline

Show system name:
hostname
cat /proc/sys/kernel/hostname

Show system's IP address:
hostname -i # Local IP
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' # Global IPv4
ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p' # Global IPv4

Show client's IP address in a SSH connection:
echo $SSH_CLIENT | awk '{print $1}'
echo $SSH_CONNECTION | awk '{print $1}' # Note that $SSH_CONNECTION (not processed with awk) also contains the server's IP address
echo "$(whoami) (`echo $SSH_CLIENT | awk '{print $1}'`) @ $(hostname) ($(hostname -i))"; # client (client IP) @ host (host IP)

Change system name as NEW_NAME:
hostname NEW_NAME
jed /etc/hostname # change it as NEW_NAME
jed /etc/hosts # you'd better also add NEW_NAME as an alias hostname for 127.0.0.1 (localhost)

Show system information:
uname # Show Linux (which is the case of Debian) or FreeBSD.
uname -a # Show Linux (or FreeBSD), Machine Name, Kernel version, Distribution, Distribution version, Platform.
cat /etc/issue # Welcome message: contains Linux version (unless otherwise edited by the user)
cat /etc/os-release # Get Distribution Name and Version
awk -F'=' '/^ID=/ {print $2}' /etc/os-release # Get Distribution ID with quotes
awk -F'=' '/^ID=/ {print $2}' /etc/os-release | sed -e 's/"//g' # Get Distribution ID without quotes
awk -F'=' '/^ID=/ {print $2}' /etc/os-release | tr -d '"' # Get Distribution ID without quotes
awk -F'=' '/^NAME=/ {print $2}' /etc/os-release # Get Distribution Name with quotes
awk -F'=' '/^NAME=/ {print $2}' /etc/os-release | sed -e 's/"//g' # Get Distribution Name without quotes
awk -F'=' '/^NAME=/ {print $2}' /etc/os-release | tr -d '"' # Get Distribution Name without quotes
awk -F'=' '/^VERSION=/ {print $2}' /etc/os-release # Get Distribution Version with quotes
awk -F'=' '/^VERSION=/ {print $2}' /etc/os-release | sed -e 's/"//g' # Get Distribution Version without quotes
awk -F'=' '/^VERSION=/ {print $2}' /etc/os-release | tr -d '"' # Get Distribution Version without quotes
awk -F'=' '/^VERSION_ID=/ {print $2}' /etc/os-release # Get Distribution Version ID with quotes
awk -F'=' '/^VERSION_ID=/ {print $2}' /etc/os-release | sed -e 's/"//g' # Get Distribution Version ID without quotes
awk -F'=' '/^VERSION_ID=/ {print $2}' /etc/os-release | tr -d '"' # Get Distribution Version ID without quotes
awk -F'=' '/^PRETTY_NAME=/ {print $2}' /etc/os-release # Get Distribution Pretty Name (Name and Version) with quotes
awk -F'=' '/^PRETTY_NAME=/ {print $2}' /etc/os-release | sed -e 's/"//g' # Get Distribution Pretty Name (Name and Version) without quotes
awk -F'=' '/^PRETTY_NAME=/ {print $2}' /etc/os-release | tr -d '"' # Get Distribution Pretty Name (Name and Version) without quotes
lsb_release -a # Get Distribution Name and Version (more detailed than /etc/os-release )
lsb_release --description|awk '{$1 = ""; print $0}'|sed 's/^ //g' # Get Distribution Pretty Name (more detailed than /etc/os-release )
lsb_release -ds # Get Distribution Pretty Name (more detailed than /etc/os-release )
cat /etc/debian_version # Debian version
echo $XDG_SESSION_TYPE # Show the Display Server in use (for example, x11, or tty for textual environment)
screenfetch # Show basic information about the system (it can be installed with apt install screenfetch )
neofetch # Show basic information about the system with some more detail than screenfetch (it can be installed with apt install neofetch )

Linux Kernel:
uname -r # Show current Kernel version
cat /proc/sys/kernel/osrelease # Show current Kernel version
dpkg --list | egrep -i --color 'linux-image|linux-headers' # List Kernel images present
dpkg --list | egrep -i 'linux-image|linux-headers' | wc -l # Count Kernel images present
dpkg --list | grep -i -E 'linux-image|linux-kernel' | grep '^ii' # List Kernel images currently installed
dpkg --list | grep -i -E 'linux-image|linux-kernel' | grep '^ii' | wc -l # Count Kernel images currently installed
apt-get --purge autoremove # Remove old versions of the Kernel

Init System:
cat /proc/1/comm # Command used to start the first process (that is, the Init System, which is normally systemd on Debian).
ps -A | awk -F' ' '$1 == "1"' # Show the process for PID #1 (which should be the Init System, normally systemd on Debian).
systemctl --version # Show systemd version and its features configured when it was built.
systemctl --version | head -n 1 # Show systemd version without its features.

Runlevel
runlevel # Show the current runlevel
who -r | sed 's/^ *//g' # Show the current runlevel and the time it started
ls -d /etc/rc*.d # List the directories containing the scripts for the corresponding runlevel (this is for the distributions that follow System V style, like Debian. Otherwise for distributions that follow BSD style ls /etc/rc.d/rc.* lists all the runlevel scripts)

Show information about all loaded module:
lsmod

System Journal (Systemd Logs)
journalctl --system # Show the system journal, oldest entries first by default
journalctl --system -r # Show the system journal, newest entries first
journalctl -u UNIT # Show the journal for the given unit (for example: journalctl -u apache2 ), oldest entries first by default
journalctl -u UNIT -r # Show the journal for the given unit (for example: journalctl -u apache2 -r ), newest entries first

Show the kernel ring buffer (to print out the bootup messages):
dmesg

Show last 20 lines of the system messages file:
tail --lines=20 /var/log/messages

System Up Marker:
By default, on most Debian based distributions up to Debian Etch, every 20 minutes syslog marks the message file with "-- MARK --" to log that the system is up and running.

You can modify this behavior by editing the syslog startup file:
jed /etc/init.d/sysklogd

Locate the line that defines the variable SYSLOGD (generally, SYSLOGD="" ). If it's missing you can add it at the beginning of the configuration file, where other variables are defined.
and use the switch -m to set the delay between marks in minutes, or set it to 0 to disable the notification.
Example: SYSLOGD="-m 60" marks the message file every hour, SYSLOGD="-m 0" disable the notification.

Restart syslog to make the change effective:
/etc/init.d/sysklogd restart

After Etch, the time marker is disabled by default. You can enable it editing the rsyslog configuration file and enabling the immark module (which is commented out):
jed /etc/rsyslog.conf
module(load="immark")  # provides --MARK-- message capability

You should also be able to set the delay between marks setting the RSYSLOGD_OPTIONS variable in rsyslog, unfortunately RSYSLOGD_OPTIONS is ignored:
jed /etc/init.d/rsyslog
RSYSLOGD_OPTIONS="-m 60" marks the message file every hour

Restart syslog to make the change effective:
/etc/init.d/rsyslog restart

Check last marks in syslog and messages:
# Time marks should coincide in both syslog and messages
grep "MARK" /var/log/syslog | tail --lines=10 ; echo ; grep "MARK" /var/log/messages | tail --lines=10

# Check last times rsyslog was stopped
grep "] exiting" /var/log/messages | tail --lines=10 # You could also grep "] exiting" /var/log/syslog | tail --lines=10

# Check last times rsyslog was started
grep "] start" /var/log/messages | tail --lines=10 # You could also grep "] start" /var/log/syslog | tail --lines=10


Start Debian base system configuration tool:
base-config

Show Hardware info:
dmidecode -t TYPE_OR_SUPERTYPE # Valid types are: 0: BIOS, 1: System, 2: Base Board, 3: Chassis, 4: Processor, 5: Memory Controller, 6: Memory Module, 7: Cache, 8: Port Connector, 9: System Slots, 10: On Board Devices, 11: OEM Strings, 12: System Configuration Options, 13: BIOS Language, 14: Group Associations, 15: System Event Log, 16: Physical Memory Array, 17: Memory Device, 18: 32-bit Memory Error, 19: Memory Array Mapped Address, 20: Memory Device Mapped Address, 21: Built-in Pointing Device, 22: Portable Battery, 23: System Reset, 24: Hardware Security, 25: System Power Controls, 26: Voltage Probe, 27: Cooling Device, 28: Temperature Probe, 29: Electrical Current Probe, 30: Out-of-band Remote Access, 31: Boot Integrity Services, 32: System Boot, 33: 64-bit Memory Error, 34: Management Device, 35: Management Device Component, 36: Management Device Threshold Data, 37: Memory Channel, 38: IPMI Device, 39: Power Supply; Valid supertypes are: bios (0, 13), system (1, 12, 15, 23, 32), baseboard (2, 10), chassis (3), processor (4), memory (5, 6, 16, 17), cache (7), connector (8), slot (9).
dmidecode -t 6|grep -i "Size" # Return installed memory banks
dmidecode -t 1|grep -i "Manufacturer\|Product\|Serial" # Return system's Manufacturer, Product Name, and Serial Number

apt install lshw
lshw # Return hardware information about all classes of hardware
lshw -c cpu # Return information about the CPU
lshw -c display # Return information about the display card
lshw -c memory # Return information about memory
lshw -c disk # Return information about disks
lshw -c network # Return information about network interfaces

Show RAM info:
cat /proc/meminfo
grep MemTotal /proc/meminfo  # return total RAM seen by the system
egrep 'Mem|Cache|Swap' /proc/meminfo # return information about RAM, Cache, Swap
vmstat -s # show information about memory activity

Show memory usage:
free # show total, used, free, available memory in Bytes
free -w # show total, used, free, available memory in Bytes, in wide format (separating values for buffers and cache)
free -k # show total, used, free, available memory in KB
free -m # show total, used, free, available memory in MB
free -h # show total, used, free, available memory in human readable format
free -wh -c 3 -s 1 # show memory usage 3 times with 1 second interval
free -h | xargs | awk '{print "Memory: Size: "$8" Used: "$9" Free: "$10" Avail: "$13}' # Return Total, Used, Free, Available Memory

Swap memory:
cat /proc/sys/vm/swappiness # Show system Swappiness (Range: 0 - 100 ; 0: Never use Swap (disabled) , 100: Always use Swap ; Default: 60 )
sysctl vm.swappiness=10 # Set Swappiness to 10
swapoff -a # Disable Swap memory
swapon -a # Enable Swap memory (wait about 30 seconds after disabling Swap before to enable it again, to let your system clear Swap memory proprerly
swapon --show # Show summary of swap devices and their swap memory usage in human readable format
swapon --show --noheadings --raw --bytes # Show summary of swap devices and their swap memory usage in bytes without headers
swapon --show --noheadings --raw --bytes | xargs | awk '{print $1","$3","$4}' # Show swap memory device name and usage in bytes, comma separated
swapon --show --noheadings --raw | xargs | awk '{print "Swap File: Dev: "$1" Total: "$3" Used: "$4}' # Show swap memory device name and usage in verbose human readable format
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done # List Swap space usage per process
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r # List Swap space usage per process and sort results

Virtual memory statistics: 
vmstat # report information about processes, memory, paging, block IO, traps, and cpu activity.
vmstat -s # event counters and memory statistics
vmstat -d # disk statistics

Show CPU info:
lscpu
lscpu | grep "mode(s)" # return CPU op-modes (32-bit, 64-bit)
lscpu | grep "Byte Order" # return CPU Byte Order (Little Endian, Big Endian)
cat /proc/cpuinfo
grep 'model name' /proc/cpuinfo # return CPU model
grep -c 'processor' /proc/cpuinfo # count CPU cores
grep 'flags' /proc/cpuinfo # return available features of the CPU
cat /proc/loadavg # show load average of the system: the first three fields in this file are load average figures giving the number of jobs in the run queue (state R) or waiting for disk I/O (state D) averaged over 1, 5, and 15 minutes. They are the same as the load average numbers given by uptime(1) and other programs. The fourth field consists of two numbers separated by a slash (/). The first of these is the number of currently executing kernel scheduling entities (processes, threads); this will be less than or equal to the number of CPUs. The value after the slash is the number of kernel scheduling entities that currently exist on the system. The fifth field is the PID of the process that was most recently created on the system.
grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}' # show CPU load
uptime | awk -F'[a-z]:' '{print $2}' # Show load average of the system over the last 1, 5, and 15 minutes.
echo -n "CPU average load (Cores: "; grep 'cpu cores' /proc/cpuinfo | xargs | awk '{printf $4}'; echo -n "): "; uptime | awk -F'[a-z]:' '{print $2}' | xargs | awk '{print "1 m: "$1" 5 m: "$2" 15 m: "$3}'; # Show load average of the system over the last 1, 5, and 15 minutes (verbose).

Show Display info:
cat /sys/class/graphics/*/name # Show Display Adapter Name
cat /sys/class/drm/*/modes # Show available Video modes
cat /sys/class/graphics/*/modes # Show current Video mode
cat /sys/class/graphics/*/virtual_size # Show Virtual Display resolution
cat /sys/class/graphics/*/bits_per_pixel # Show color depth

List all PCI buses and devices:
lspci

Show system temperature (if system supports ACPI):
apt-get install acpi
acpi -t




Please DONATE to support the development of Free and Open Source Software (PayPal, Credit Card, Bitcoin, Ether)

Page issued on 25-Sep-2022 04:44 GMT
Copyright (c) 2022 Geody - Legal notices: copyright, privacy policy, disclaimer