Skip to content

Instantly share code, notes, and snippets.

@mnadjit
Last active May 24, 2022 08:47
Show Gist options
  • Save mnadjit/cb5853ede5359990699d2e055d83fbbf to your computer and use it in GitHub Desktop.
Save mnadjit/cb5853ede5359990699d2e055d83fbbf to your computer and use it in GitHub Desktop.
Linux Common commands to get info about a machine, its hardware, status, monitoring, administration and some useful tools.

Linux Notes

Table of contents

General

Boot (UEFI)

Get the default kernel used by GRUB2:

grubby --default-index OR grubby --default-kernel

Change the default bootloader to GRUB2:

grubby --set-default-index=0 OR grubby --set-default-kernel=$path_to_kernel_file

  • Kernel files are found here: /boot/vmlinuz-<version>

Update Grub2 configuration file

After making changes to /etc/default/grub you need to run grub2-mkconfig for changes to be written to the grub.cfg file.

  • Fedora

sudo grub2-mkconfig -o $boot_partition/$boot_dir_name/fedora/grub.cfg

  • Find out where boot partition is mounted using lsblk or df
  • e.g. if /dev/sda1 is mounted at /boot/efi and there is subdirectory EFI under it, then:

sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg



System Information

Hardware Overview

sudo lshw -short
sudo dmidecode

  • more details (Desktop Management Interface)

CPU

sudo lshw -businfo | grep cpu

  • shortest CPU description

lscpu

  • CPU overview

cat /proc/cpuinfo

  • Details for each core

sudo dmidecode -t processor

  • CPU details

GPU

lspci -vnn | egrep -i vga|3d

Storage

sudo lshw -businfo | grep disk

  • Disk size and model

lsblk -pf

  • Get info about all block devices (-p: paths; -f: filesystems label and UUID)

df -h

  • Get the size of partitions (-h: human readable)

sudo fdisk -l

  • list partitions with more details

sudo dnf install ncdu
ncdu $path_to_directory

  • NCDU app for displaying disk usage

USB

  • lsusb: simple short list of USB devices
  • lsusb -t: in a tree format
  • lsusb -tv: in a tree format with vendor and product IDs

Network

  • ip addr: list of network interfaces with their IP addresses
  • ip link: list of network interfaces
  • ip link show: show details of network interfaces
  • ip link set dev <interface> up: bring up interface
  • ip link set dev <interface> down: bring down interface

Memory

  • free: show memory usage in bytes
  • free -mh: show memory usage in MegaBytes and in human readable format
  • cat /proc/meminfo: show memory usage in human readable format

Bluetooth

BluetoothCtl:

  • bluetoothctl: A tool in the BlueZ package
    • power on
    • agent on
    • default-agent
    • scan on
    • trust <deviceuuid>
    • pair <deviceuuid>
    • connect <deviceuuid> HCI tool:
  • hcitool dev
  • hci -i <dev> scan
  • To be added

Fonts

General

  • Copy any font file e.g. in .ttf or .otf format to the fonts folders usr/share/fonts or /usr/local/share/fonts
  • To make sure it is available for all users, run:
    • fc-list
  • To update the cache for programs like libre office, run:
    • fc-cache
  • To get the current font used by the terminal, run:
    • gsettings get org.gnome.desktop.interface monospace-font-name
  • In Gnome, can use Tweaks application to change the font.
  • To change the font in the terminal, run:
    • gsettings set org.gnome.desktop.interface monospace-font-name $font_name

Patching a font file with glyphs

Use Nerd-Fonts

  1. Install fontforge

sudo dnf install fontforge

  • you can also use fontforge to view the content of the font file and make adjustments
  1. Create a folder and make sure it contains the following items

    • font-patcher python script
      • Download from github

      wget https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/font-patcher

    • glyphs folder:
      • Download /src/glyphs folder from github

      svn checkout https://github.com/ryanoasis/nerd-fonts/trunk/src/glyphs

  2. Run the following command to patch a font file

fontforge -script font-patcher -c -w --careful -out $output_directory $font_file_path

  • -c: Complete; meaning patch all glyphs like fontawesome, octicons, codicons, etc. to the font file
  • -w: Windows Compatible; Make the font name short so it can be used in Windows as well.
  • --careful: Do not overwrite an already patched character



Fedora / Gnome

     


Administration

User Management

  • Fedora Docs
  • less /etc/passwd: get a list of all users and their default shell
  • less /etc/group: get a list of all available groups
  • groups: get a list of groups the user is actively part of
  • groups <user>: get a list of groups user is assigned to - might need re-log in for newly assigned ones to take effect
  • sudo passwd: change password
  • sudo useradd: add user
  • sudo userdel: delete user
  • sudo usermod: modify user
  • sudo usermod -aG <group> <user>: add user to group e.g. wheel, libvirt or docker

Permissions

  • Fedora Docs
  • sudo chmod: change permissions
    • sudo chmod -R u+rwX,go-w: recursively (-R) add read/write/execute permissions to user only; for group and others only remove write permission
    • sudo chmod 753 <file>: set permissions as rwx for user, r-x for group and -wx for others
  • sudo chown: change ownership

Firewall

  • Fedora Docs
  • sudo firewall-cmd --list-all: list all firewall rules
  • sudo firewall-cmd --zone=public --list-ports: list all ports
  • sudo firewall-cmd --zone=public --add-service=<service>: add service
  • sudo firewall-cmd --zone=public --remove-service=<service>: remove service
  • sudo firewall-cmd --zone=public --add-port=<port>/<protocol>: add port
  • sudo firewall-cmd --zone=public --remove-port=<port>/<protocol>: remove port

Package Management

  • sudo dnf update: update all packages
  • sudo dnf upgrade: upgrade all packages
  • sudo dnf install <package>: install package
  • sudo dnf remove <package>: remove package
  • sudo dnf clean all: clean all packages
  • sudo dnf autoremove: remove all packages that are no longer needed
  • sudo dnf history list: list all packages installed
  • sudo dnf history info <package>: show details of package
  • sudo dnf history undo <package>: undo package installation
  • Additional Repositories
    • RPM Fusion Repositories
      • Fedora-Docs
      • sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm: RPM Fusion Free Repository
      • sudo dnf install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm: RPM Fusion Non-Free Repository
    • Ad-hoc Repositories
      • Fedora Docs
      • sudo dnf config-manager --add-repo <repo_url>: add repository
      • sudo dnf config-manager --set-enabled <repo_name>: enable repository

Useful Tools

General

  • vim: vim text editor
  • pytop: top command
  • ncdu: NCdu disk usage
  • wireshark: network sniffer
  • nmap: nmap network scanner
  • neofetch: Get system info
  • Citrix: Citrix Workspace
  • ICAClient: Citrix ICAClient client
  • timeshift: Backup and restore linux - excluding personal directories
  • dnfdragora: A package-based graphical frontend for Dnf
  • rambox: All-in-one messaging and email client
  • bleachbit: Remove unwanted files and clean up the system
  • stacer: System monitoring and cleaning utility - view all startup programs, services, disk usage, and more

Gnome Extensions

Flatpaks

  • General
    • Add flathub repository:
      • flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
    • Run flatpak:
      • flatpak run <flatpak_id>
  • Applications:
    • onlyoffice-desktopeditors: OnlyOffice desktop editors
      • flatpak install flathub org.onlyoffice.desktopeditors: Install OnlyOffice desktop editors
    • vscode: Visual Studio Code
      • flatpak install flathub com.visualstudio.code: Install Visual Studio Code

Snaps

  • General
    • Install Snap:
      • sudo dnf install snapd
  • Install Snap Packages:
    • Sosumi:
      • sudo snap install sosumi

Multimedia

  • Fedora Docs
  • sudo dnf install gstreamer1-plugins-{bad-\*,good-\*,base} gstreamer1-plugin-openh264 gstreamer1-libav --exclude=gstreamer1-plugins-bad-free-devel
  • sudo dnf install lame\* --exclude=lame-devel
  • sudo dnf group upgrade --with-optional Multimedia

DateTime

  • Fedora Docs
  • sudo timedatectl set-timezone Australia/Melbourne: set timezone

Set Locale

  • localectl status: show current locale
  • localectl list-locales: list all locales
  • sudo localectl set-locale LANG=en_AU.utf8: set locale to Australian English and UTF-8 encoding
  • localectl list-keymaps: list all keymaps
  • localectl set-keymap us: set keymap to US

Virutalization

  • sudo dnf groupinstall --with-optional virtualization

Development Tools

  • sudo dnf groupinstall "Development Tools"
# GRUB boot loader configuration
GRUB_TIMEOUT="2"
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DISABLE_SUBMENU="true"
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet nomodeset"
# GRUB_CMDLINE_LINUX="resume=UUID=a35225e0-1a30-49d3-9868-2acfb7357ba1 rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1"
GRUB_CMDLINE_LINUX="resume=UUID=a35225e0-1a30-49d3-9868-2acfb7357ba1 rhgb quiet"
# Preload both GPT and MBR modules so that they are not missed
#GRUB_PRELOAD_MODULES="part_gpt part_msdos"
# Uncomment to enable booting from LUKS encrypted devices
#GRUB_ENABLE_CRYPTODISK="y"
# Set to 'countdown' or 'hidden' to change timeout behaviour,
# press ESC key tyo display menu
GRUB_TIMEOUT_STYLE="menu"
# Uncomment to use basic console
GRUB_TERMINAL_INPUT="console"
# Uncomment to disable graphical terminal
#GRUB_TERMINAL_OUTPUT="console"
# The resolution used on graphical termina
# note that you can use only modes which your graphics card supports via VBE
# you can see them in GRUB commandline with the command 'vbeinfo'
GRUB_GFXMODE="auto"
# Uncomment to allow the kernel to use the same resolution used by grub
#GRUB_GFXPAYLOAD_LINUX="keep"
# Uncomment if you want GRUB to pass to the Linux kernel the old parameter
# format "root=/dev/xxx" instead of "root=/dev/disl/by-uuid/xxx"
#GRUB_DISABLE_LINUX_UUID="true"
# Uncomment to disable generation of recovery mode menu entries
GRUB_DISABLE_RECOVERY="true"
# Uncomment to stop GRUB from trying to find other OS'es installed on the machine
GRUB_DISABLE_OS_PROBER="true"
# Uncomment to make GRUB remember the last selection. This requires setting 'GRUB_DEFAULT="saved"'
GRUB_DEFAULT="saved"
GRUB_SAVEDEFAULT="true"
# Load and build menus from configuration files
GRUB_ENABLE_BLSCFG="true"
# Grub Theme settings
export GRUB_COLOR_NORMAL="light-gray/black"
export GRUB_COLOR_HIGHLIGHT="magenta/black"
GRUB_THEME="/usr/share/grub/themes/theme_dir_name/theme.txt"
# Uncomment to set background image
#GRUB_BACKGROUND="/path/to/wallpaper"
# Uncomment to get a beep at GRUB start
#GRUB_INIT_TUNE="480 440 1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment