Skip to content

Instantly share code, notes, and snippets.

@coulterpeterson
Last active February 11, 2025 19:17
Show Gist options
  • Save coulterpeterson/9df1b56f5a2b464fd1822c87a9a766f7 to your computer and use it in GitHub Desktop.
Save coulterpeterson/9df1b56f5a2b464fd1822c87a9a766f7 to your computer and use it in GitHub Desktop.
Various Handy Linux Distro Commands

Note: Assume a debian-based distro unless otherwise noted

Mount USB/Drives

sudo fdisk -l
mkdir /media/usb-drive
mount /dev/sdc1 /media/usb-drive/

umount /media/usb-drive

Permanent USB Mount

  • ls -l /dev/disk/by-uuid/*
  • ( In /etc/fstab ): /dev/disk/by-uuid/8765-4321 /media/usb-drive vfat 0 0
  • mount -a

Automount NTFS drive on boot

Share folder between NTFS drive and Linux ext4 drive (symlink a folder)

  • ln -s /media/gamedisk/SteamLibrary/steamapps/common/rocketleague/ ~/.steam/steam/steamapps/common/

Mount SMB share on boot

  • Guide: https://askubuntu.com/a/157140/1967475
  • sudo apt-get install cifs-utils
  • sudo mkdir /media/myshare
  • sudo nano /etc/fstab
  • Add a line like this: //servername/sharename /media/myshare cifs uid=username,credentials=/home/username/.smbcredentials 0 0
  • nano ~/.smbcredentials
  • Add credentials like so:
username=myusername
password=mypassword
domain=WORKGROUP
  • chmod 0600 ~/.smbcredentials
  • Finally test the mount with sudo mount -a
    • If first mount was done incorrectly, first unmount with sudo umount /media/myshare
  • Should see the share's files with ls /media/myshare

Create 'restore point' backup snapshot of the system

Add directory to path

Permanent Addition (System-wide)

Edit the /etc/profile file using a text editor (e.g., sudo nano /etc/profile). Add the following line at the end of the file: export PATH=$PATH:/new/directory/path (replace /new/directory/path with the actual path you want to add). Save and close the file. Reload the /etc/profile file by running source /etc/profile or restarting your system.

Permanent Addition (User-specific)

Edit your user’s ~/.profile file using a text editor (e.g., nano ~/.profile). Add the following line at the end of the file: export PATH=$PATH:/new/directory/path (replace /new/directory/path with the actual path you want to add). Save and close the file. Reload your user’s profile by running source ~/.profile or restarting your terminal.

KDE-Specific

Make Krunner font bigger

  • kquitapp5 krunner
  • nano ~/.config/krunnerrc
  • Add this (first number is pointsize) - thanks Reddit thread:
[General]
...
font=Noto Sans,18,-1,5,50,0,0,0,0,0

Disable Calendar Reminders from autostarting

  • mkdir ~/.config/autostart
  • cp /etc/xdg/autostart/org.kde.kalendarac.desktop ~/.config/autostart/
  • nano ~/.config/autostart/org.kde.kalendarac.desktop
  • Add this to the Desktop entry: Hidden=true
  • Stop the service for the current session with akonadictl stop
    • Check that it's no longer running with akonadictl status

Handy KDE Shortcuts

Enable verbose boot

From Brave AI: To enable verbose boot on Ubuntu, you need to modify the GRUB configuration file to remove the quiet and splash options. Here are the steps:

  1. Open the terminal and run the command: sudo nano /etc/default/grub
  2. Comment out the lines that start with GRUB_CMDLINE_LINUX_DEFAULT by adding a # symbol at the beginning of each line.
  3. Replace the commented-out lines with the following:
GRUB_CMDLINE_LINUX_DEFAULT=""

This will remove the quiet and splash options, enabling verbose boot.

  1. Save the changes by pressing Ctrl+X, then Y, and finally Enter.
  2. Run the command: sudo update-grub to apply the changes to the GRUB configuration.
  3. Reboot your system to see the verbose boot output.

Alternatively, you can also enable verbose boot by adding the nosplash and debug options to the GRUB command line. To do this:

  1. Open the terminal and run the command: sudo nano /etc/default/grub
  2. Add the following lines to the end of the file:
GRUB_CMDLINE_LINUX_DEFAULT="nosplash debug"
  1. Save the changes by pressing Ctrl+X, then Y, and finally Enter.
  2. Run the command: sudo update-grub to apply the changes to the GRUB configuration.
  3. Reboot your system to see the verbose boot output.

Note that the nosplash option will disable the graphical boot splash screen, and the debug option will enable verbose boot output. You can adjust these options to your preference.

References:

Enable X11 Forwarding (Linux to Linux)

  • Make sure SSH is installed on the server computer with sudo apt update && sudo apt install -y openssh-server
  • Run the server with sudo systemctl start ssh
  • Edit the config with sudo nano /etc/ssh/sshd_config and ensure the line X11Forwarding yes is uncommented
  • Restart the server with sudo systemctl restart ssh
  • Get the server IP with hostname -I
  • Connect to it from the client computer with ssh [email protected] -X
  • Launch the desired app with commands like kate and flatpak run --nosocket=fallback-x11 --socket=x11 com.brave.Browser

Misc. Little Bits

How to properly remove an additional desktop environment (like when we all test lubuntu desktop for an hour and then relapse)

Method: https://askubuntu.com/a/492522

How to prevent NoMachine/NX Server from starting on boot

sudo /etc/NX/nxserver --startmode manual

Switch between GUI and Text-based Terminals (TTY)

  • Ctrl+Alt+F[#] to switch to terminals 3 through 6
    • Once viewing a TTY, Alt+F[#] is a faster switch shortcut
  • #2 is usually the GUI
  • #1 is usually the login chooser

Edit CronTab

crontab -e

Search for file of extension type

find / -type f -name "*.env"

Tar Gzip a destination to a specified source

tar -czvf ~/destination-file-name.tar.gz /home/source

Copy remote file to local

scp <remote_username>@<IPorHost>:<PathToFile> <LocalFileLocation>

Install a program in Fedora/RHL (Dandified YUM)

sudo dnf install <package>

Show system specs with pretty logo

neofetch fastfetch

Add terminal alias

  • echo "alias sail='sh $([ -f sail ] && echo sail || echo vendor/bin/sail)'" >> ~/.bash_aliases
  • Reload bashrc which loads in bash_aliases with source ~/.bashrc

Kill a process based on the port its using

  • sudo lsof -i :45457
  • sudo kill -9 55203

Create custom application launcher shortcut (Android Studio in this example)

  • sudo nano /usr/share/applications/AndroidStudio.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name=Android Studio
Exec="/home/username/Applications/android-studio/bin/studio.sh" %f
Icon=/home/username/Applications/android-studio/bin/studio.png
Categories=Development;IDE;
Terminal=false
StartupNotify=true
StartupWMClass=jetbrains-android-studio
Name[en_GB]=android-studio.desktop

Fix JavaScript 'watch' commands throwing a file watchers limit error

Enable FSR in Linux Steam Game (Or a Windows game that uses Proton)

  • https://support.system76.com/articles/use-amd-fsr/
  • Add WINE_FULLSCREEN_FSR=1 %command% to the launch commands of the game
  • To modify the sharpening strength, use something like WINE_FULLSCREEN_FSR=1 WINE_FULLSCREEN_FSR_STRENGTH=1 %command%
  • Then just lower the resolution in game while its set to fullscreen!
  • For a non-Steam game, use Lutris settings (see article above)

Write a Windows ISO to a USB drive

  • Find the USB mount point with a graphical disk utility or use mount
  • Unmount it with a command like sudo umount /dev/sdb
  • Write the ISO with a command like sudo dd bs=4M if=Win10_22H2_English_x64v1.iso of=/dev/sdb status=progress

Snippet for .bashrc that imports a one-off SSH key like a deploy key

if [ -n "$SSH_CONNECTION" ] && [ -z "$SSH_AUTH_SOCK" ]; then
  eval "$(ssh-agent -s)"
  ssh-add ~/.ssh/deploy_key
fi

Flatpak commmands

  • List Flatpak app processes flatpak ps
  • Kill desired app with something like flatpak kill com.brave.Browser

Handy Scripts

Add a library of helper shell scripts

  • mkdir ~/scripts
  • nano ~/scripts/name-of-script.sh
    • Add your code for that script, then save
  • chmod +x ~/scripts/name-of-script.sh
  • nano ~/.bashrc and add this to the bottom of the file: export PATH=$PATH:/home/username/scripts
  • source ~/.bashrc

Fix Web Permissions

Full version (fix-web-permissions.sh)

echo 'Fixing site permissions...' ;
sudo usermod -aG www-data $USER ;
sudo chown -R $USER:www-data . ;
echo -ne '#####                     (33%)\r' ;
find . -type d -exec chmod 755 {} \;;
echo -ne '#############             (66%)\r' ;
find . -type f -exec chmod 644 {} \;;
echo -e '#######################   (100%)\r' ;
sudo chmod -R g=u . ;
git config core.fileMode false ;

Lite version (fix-web-permissions-lite.sh)

echo 'Fixing site permissions...' ;
sudo chown -R $USER:www-data . ;
echo -ne '#####                     (33%)\r' ;
echo -ne '#############             (66%)\r' ;
echo -e '#######################   (100%)\r' ;
sudo chmod -R g=u . ;
git config core.fileMode false ;

Convert MP4-codec files to .MOV for use in Davinci Resolve on Linux

~/scripts/resolve-play-nice.sh

mkdir converted;
for i in *.mp4 *.MP4 *.MOV *.mov *.mkv *.MKV; do ffmpeg -i "$i" -vcodec mjpeg -q:v 2 -acodec pcm_s16be -q:a 0 -f mov "./converted/${i%.*}.mov"; done

Set custom resolution, in particular for my Surface display while remoted in

Guide I followed: https://dev.to/ksckaan1/setting-up-custom-screen-resolution-on-linux-permanently-1abg

~/scripts/surface-resolution.sh

xrandr --newmode "2880x1920_60.00"  473.25  2880 3112 3424 3968  1920 1923 1933 1989 -hsync +vsync ;
xrandr --admode HDMI-A-0 "2880x1920_60.00" ; 
xrandr --addmode HDMI-A-0 "2880x1920_60.00" ; 
xrandr --output HDMI-A-0 --mode "2880x1920_60.00" ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment