Skip to content

Instantly share code, notes, and snippets.

@sfloess
Last active May 3, 2025 22:42
Show Gist options
  • Select an option

  • Save sfloess/7d155642f345a4f02c46955fa82425ec to your computer and use it in GitHub Desktop.

Select an option

Save sfloess/7d155642f345a4f02c46955fa82425ec to your computer and use it in GitHub Desktop.
Linux helpful tips and tricks

Linux

Helpful tips and tricks for Linux.

How-To

Quickies

  • NetworkManager
    • Setup bridge
      • nmcli connection add type bridge autoconnect yes con-name [bridge name] ifname [bridge interface name]
      • nmcli con add type bridge-slave ifname [ethernet name] master [bridge hame]
      • Example
        • nmcli connection add type bridge autoconnect yes con-name bridge ifname bridge
        • nmcli con add type bridge-slave ifname enp34s0u2u1u2 master bridge
  • gvim doesn't resize:
    • edit ~/.bashrc
    • export GVIM_ENABLE_WAYLAND=true
  • Change MAC Address: macchange -r [interface]. For example: macchange -r wlp3s0
  • Display max supported RAM: dmidecode --type 16
  • Check RAM speed: dmidecode --type 17
  • List open ports and proceses that own them:
    • lsof -i
    • netstat -lptu
    • netstat -tulpn
  • Don't use a dnsmasq lease file: --leasefile-ro
  • NIS: domainname: /etc/defaultdomain
  • Ensure laptop doesn't sleep/hibernate when lid is closed: systemctl mask suspend.target
  • When booting headless, ensure console goes blank: /etc/default/grub: GRUB_CMDLINE_LINUX_DEFAULT="... consoleblank=[seconds to blank]"
    • Example: GRUB_CMDLINE_LINUX_DEFAULT="quiet consoleblank=20"
    • Make sure once edited, you run the following to ensure it "sticks" after next boot:
      • Debian: update-grub
      • Fedora: grub2-mkconfig -o /boot/grub2/grub.cfg
  • ISO
    • Mount: mount -o loop [full path to ISO]/[ISO file name].iso [full path to mount point]. Example: mount -o loop /path/to/disk1.iso /mnt/disk
    • Write an ISO to a USB stick: dd if=[ISO file] of=/dev/[usb]. For example: dd if=red_ribbon_lxde_14.03.iso of=/dev/sdb
    • Create from CD-ROM/DVD: sudo dd if=/dev/cdrom of=/tmp/cdimg1.iso
  • mkv to mp4: ffmpeg -i [mkv file].mkv -codec copy [new name].mp4
  • webm to mp4: ffmpeg =i [webm file].webm -max_muxing_queue_size 200000 [new name].mp4
    • _Not sure about the 200000 - it's just what I am using
  • Disable notification-daemon/notify-send
  • Screen
  • Generate ssh host keys: /usr/bin/ssh-keygen -A
  • BASH
    • printf: %s, %b, %d, %x and %f
  • Alternatives
    • editor: update-alternatives --config editor
      • Fedora: export EDITOR=[path to editor]/[editor] Example: export EDITOR=/usr/bin/vim
    • java: update-alternatives --config java
    • javac: update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/open-jdk-11/bin/javac 1
  • Remove journaling ext4: tune2fs -O ^has_journal /dev/[drive]. Example: tune2fs -O ^has_journal /dev/sda1
  • Emojis
    • Install
    • Latest Versions
    • Manal Installation
      • wget https://github.com/eosrei/emojione-color-font/releases/download/v1.4/EmojiOneColor-SVGinOT-Linux-1.4.tar.gz
      • tar zxf EmojiOneColor-SVGinOT-Linux-1.4.tar.gz
      • cd EmojiOneColor-SVGinOT-Linux-1.4
      • ./install.sh
      • apt-get install ttf-bitstream-vera
  • Find default gateway: ip route show
    • Look at the default line.
    • Example:
    default via 24.211.184.1 dev brwan 
    24.211.184.0/21 dev brwan proto kernel scope link src 24.211.184.21 
    192.168.168.0/24 dev br0 proto kernel scope link src 192.168.16
    

Add Swap Space

Directions can be found here.

  • dd if=/dev/zero of=[swap file] bs=1MiB count=$(([number of GB]*2014))
  • sudo chmod 600 [swap file]
  • mkswap [swap file]
  • swapon [swap file]

Example

  • dd if=/dev/zero of=swapfile bs=1MiB count=$((2*2014))
  • sudo chmod 600 /swapfile
  • mkswap /swapfile
  • swapon /swapfile

Cron

When run, to have emails sent to an address, add to /etc/crondtab:

MAILTO=[user]@[domain]

For example: MAILTO=sfloess@mail

The basic structure can also be added to any individual user's crontab entries in the user's crontab file.

Include Git Repo in Your Prompt

.bashrc:

__compute_git_info() {
    local GIT_INFO="`git remote 2> /dev/null | tr -s '\n' '/' | rev | cut -c2- | rev` `git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/\1/'`"

    if [ "${GIT_INFO}" != "/" ]
    then
        echo " ${GIT_INFO}"
    fi
}

__prompt_command() {
    local GIT_INFO=`__compute_git_info`

    PS1="[${GIT_INFO}] \`pwd\`> "
}

export PROMPT_COMMAND=__prompt_command

TLP

Adjusts power settings (here is a link for installing). For max performance, here are a few notable settings:

TLP_ENABLE=1
TLP_DEFAULT_MODE=AC
DISK_IDLE_SECS_ON_AC=0
CPU_SCALING_GOVERNOR_ON_AC=performance
CPU_HWP_ON_AC=performance
CPU_MIN_PERF_ON_AC=100
CPU_MAX_PERF_ON_AC=100
CPU_BOOST_ON_AC=1
SCHED_POWERSAVE_ON_AC=0
ENERGY_PERF_POLICY_ON_AC=performance
SATA_LINKPWR_ON_AC="max_performance max_performance"

Additionally, there are two settings for CPU scaling that'll be dependent upon your CPU: CPU_SCALING_MIN_FREQ_ON_AC and CPU_SCALING_MAX_FREQ_ON_AC

To list your CPU settings invoke the following: tlp-stat -p

As an example, one of my servers lists the aforementioned as: /sys/devices/system/cpu/cpu1/cpufreq/scaling_available_frequencies = 3000000 2667000 2333000 2000000 [kHz]

For this machine, I have these settings:

CPU_SCALING_MIN_FREQ_ON_AC=3000000
CPU_SCALING_MAX_FREQ_ON_AC=3000000

Apps

  • nexus.service
[Unit]
Description=Nexus Service
After=network.target

[Service]
Type=forking
WorkingDirectory=/opt/nexus/bin
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
Restart=on-abort
TimeoutStartSec=600
TimeoutStopSec=600
RestartSec=600

[Install]
WantedBy=multi-user.target
  • activemq.service
[Unit]
Description=ActiveMQ Service
After=network.target

[Service]
Type=forking
PIDFile=/opt/apache-activemq/data/activemq.pid
WorkingDirectory=/opt/apache-activemq/bin
ExecStart=/opt/apache-activemq/bin/activemq start
ExecStop=/opt/apache-activemq/bin/activemq stop
Restart=on-abort
TimeoutStartSec=600
TimeoutStopSec=600
RestartSec=600

[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment