Linux - Smart Linux Tricks

From Da Nerd Mage Wiki
Jump to navigation Jump to search

A collection of tips & tricks for using Linux...

Restart a service

  • sudo service FOOBAR restart

or

  • sudo systemctl restart FOOBAR.service

Where "FOOBAR" is the name of the service you want to restart...

Taking a screenshot (in Mint Cinnamon)

Here are the default shortcuts. You can customize them in Keyboard Settings, as shown in the image that started this post.

Action Shortcut
Take a screenshot Print
Take a screenshot of a window Alt + Print
Take a screenshot of an area Shift + Print
Copy screen to clipboard Control + Print
Copy window to clipboard Control + Alt + Print
Copy area to clipboard Shift + Control + Print
Toggle recording desktop Shift + Control + Alt + R

Print may have its own special label on your keyboard. On mine the Print key is labeled PrtSc.

Testing Network Connectivity

A handy little script:

#!/bin/bash 
if nc -zw1 pfSense 443
then
  echo "We have DNS..."
else
  echo "NOPE!  No DNS..."
  sudo systemctl restart systemd-resolved
  exit
fi

Uses netcat (nc) to simply check if the router (pfsense) is currently findable by name & responding to HTTPS (port 443).

Then either tells you if it's OK or asks for your password to restart the DNS resolver.

Less "Useful" Stuff

Kind of a silly little on-liner to paint a rainbow in the terminal...

  • yes "$(seq 231 -1 16)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .02; done

Create custom fortune cookies files

  1. Open your favourite editor and add the strings that you want to be shown when running "fortune" in terminal. BE SURE to add a single line with a letter % in it, between every string.
  2. Save this file to whatever file name you want; this guide uses "yourlist" as example.
  3. When done adding strings, the following command will create a .dat file for your cookie file, which contains a header structure and a table of file offsets for each group of lines. This allows random access of the strings.
    • strfile -c % yourlist yourlist.dat
  4. Run fortune yourlist to eat the fruit of your work. That's it!
  5. Might wanna put this in /usr/share/games/fortunes if you want it to actually work tho...

(Do note... It's a sudo thing...)

Some other tips...