Skip to content

Instantly share code, notes, and snippets.

@dxmekch
Forked from mnemocron/Linux CLI cheat sheet.md
Last active June 6, 2020 14:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dxmekch/600b32f1498c1a764965eaa309278911 to your computer and use it in GitHub Desktop.
Save dxmekch/600b32f1498c1a764965eaa309278911 to your computer and use it in GitHub Desktop.

CLI cheat sheet

My personal cheatsheet for using the Linux command line.



Flighttracker

Warroom monitoring of all adsb receiving devices

Install netdata from https://learn.netdata.cloud/docs/agent/packaging/installer

bash <(curl -Ss https://my-netdata.io/kickstart.sh)
"apply code from netdata.cloud to add device"

RaspberryPi Setup

Install Raspbian Lite (headless) place file wpa_supplicant.conf in boot directory

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<Insert 2 letter ISO 3166-1 country code here e.g. CH, US>

network={
 ssid="<Name of your wireless LAN>"
 psk="<Password for your wireless LAN>"
}

place empty file named ssh to enable ssh

change hostname

sudo hostname -b
sudo nano /etc/hostname
sudo nano /etc/hosts
sudo hostname

Make sure the file under /etc/hostname includes the new hostname.

dump1090 Installation RaspberryPi

Make all updates

sudo apt-get install build-essential debhelper librtlsdr-dev pkg-config dh-systemd libncurses5-dev libbladerf-dev git screen
git clone https://github.com/flightaware/dump1090.git
cd dump1090
sudo dpkg-buildpackage -b

dump1090

cd dump1090
screen -S dump1090
ps aux | grep dump
kill pid
./dump1090 --mlat --forward-mlat --net --net-ro-port 30002 --net-bo-port 30005 --fix --modeac --gain -10 --quiet &
CTRL + A then D to leave screen
screen -r => to reattach

Alternatively for cli output:

./dump1090 --mlat --forward-mlat --net --net-ro-port 30002 --net-bo-port 30005 --fix --modeac --gain -10 --interactive --interactive-ttl 60

dump1090-1.15 (deb)

./dump1090 --mlat --forward-mlat --net --net-ro-port 30002 --net-bo-port 30005 --fix --modeac --gain -10 --enable-agc --interactive --interactive-ttl 60 --stats

readsb

sudo bash -c "$(wget -q -O - https://raw.githubusercontent.com/wiedehopf/adsb-scripts/master/readsb-install.sh)"

PiAware

run as root

apt install build-essential debhelper tcl8.6-dev autoconf python3-dev python3-venv dh-systemd libz-dev
git clone https://github.com/flightaware/piaware_builder.git
./sensible-build.sh bionic
cd package-bionic/
dpkg-buildpackage -uc -us -b
cd ../
./apt install piaware_*.deb

https://discussions.flightaware.com/t/how-piaware-feeders-are-identified-updated-2017-07-16/19811/60

fr24feed

https://forum.flightradar24.com/threads/12402-How-to-set-up-a-feeder-using-64-bit-Ubuntu-Linux-on-Intel-platform



MySQL / MariaDB

Login

mysql -u [username] -p [pw]

Count the average number of id's in a table (decimal output)

SELECT COUNT(*) * 1.0 / COUNT(DISTINCT DATE([Column])) FROM [Table];

Select all records in a table where the value is smaller than X

SELECT * FROM [Table] WHERE [Column] < X

Select a Databse

USE [Database];

Show all tables in a Database

SHOW TABLES;

Import .sql.zip file

unzip -p dbdump.sql.zip | mysql -u root -p [yourdbname]

Show commands

SHOW DATABASES
SHOW TABLES
SHOW OPEN TABLES
SHOW COLUMNS
SHOW KEYS
SHOW VARIABLES
SHOW STATUS
SHOW TABLE STATUS
SHOW PROCEDURE STATUS
SHOW FUNCTION STATUS
SHOW CHARACTER SET
SHOW COLLATION

phpMyAdmin

Directory

/usr/share/phpmyadmin

Fix count() issue

sudo sed -i "s/|\s*\((count(\$analyzed_sql_results\['select_expr'\]\)/| (\1)/g" /usr/share/phpmyadmin/libraries/sql.lib.php

Upgrade

cd /usr/share/
sudo mv phpmyadmin phpmyadmin_old_version
wget "newest version"
sudo rm -rf phpMyAdmin-4.8.3-all-languages
tar -xvf phpMyAdmin*
sudo mv phpMyAdmin-4.8.3-all-languages phpmyadmin
cd phpmyadmin_old_version
sudo cp config.inc.php ../phpmyadmin/config.inc.php
sudo cp -r themes ../phpmyadmin/
cd ..
cd phpmyadmin
sudo mkdir tmp
sudo chmod 777 /usr/share/phpmyadmin/tmp

MariaDB DSM

Restart MariaDB on DSM

/usr/syno/bin/synopkg restart MariaDB

./mysql location

/volume1/@appstore/MariaDB10/usr/local/mariadb10/bin

my.cnf dir

/var/packages/MariaDB10/etc/my.cnf

GIT

Configure GIT

git config --global user.email "user.name@email.ch"
git config --global user.name "Name Surname"

Commit to master

git init
git add README.md
git commit -m "initial commit"
git remote add origin https://github.com/user/repo.git
git push -u origin master
git pull
git status
git branch
git branch dingsbums
git checkout dingsbums
git git add -A
git commit
git push
(git push --set-upstream origin dingsbums)

Samba

To add a new Samba user, you first have to create a new Unix user.

sudo usera --shell /bin/false USER    # new unix user
sudo passwd USER                        # set password
sudo smbpasswd -a USER                  # create samba user


HDD TEMP

sudo smartctl -A /dev/sda -d megaraid,1 | grep -i temperature


Linux Subsystem for Windows

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Youtube dl

youtube-dl -x —audio-format mp3 -f bestaudio -l https://www.youtube.com/playlist?list=

Get file via SSH

scp your_username@remotehost.edu:foobar.txt /local/dir

Port Knocking

echo "ping" >/dev/udp/$host/$port

Zip / Unzip

.tar.bz2

tar -jxvf file.tar.bz2

.tar.xz

tar xvfJ file.tar.xz

.tar.gz

tar -zxvf file.tar.gz

.gz

gunzip file.gz

Zip something

zip foo.zip foo

Zip recursively

zip -r file.zip directory/

GIT

Configure GIT

git config --global user.email "user.name@email.ch"
git config --global user.name "Name Surname"

Commit to master

git init
git add README.md
git commit -m "initial commit"
git remote add origin https://github.com/user/repo.git
git push -u origin master

Samba

To add a new Samba user, you first have to create a new Unix user.

sudo usera --shell /bin/false USER    # new unix user
sudo passwd USER                        # set password
sudo smbpasswd -a USER                  # create samba user

Burning .iso to a USB drive

lsblk -l            #find the usb drive
umount /dev/sdX
bs=4MB if=file.iso of=/dev/sdX

SSL

Check for how long your SSL certificate remains valid.

openssl x509 -noout -dates -in /etc/letsencrypt/live/yourdomain.tld/cert.pem

C / C++

Nixcraft: How To Compile And Run a C/C++ Code In Linux

Compile a C++ file

g++ CODE.cpp -o BINARY.exe

Compile a C file

gcc CODE.c -o BINARY.exe

Downolad

Recursively download

wget -r -np -nH —cut-dirs=2 -R index.html http://maven.jzy3d.org/releases/org/jzy3d/

Directory and Files

Size of a directory

du -sh DIR/

Recursively copy all files of type

find DIR -iname \*.TXT -exec cp {} DESTINATION \;

Random Filename argument

echo `ls dir | sort -R | tail -n 1`

Installation

sudo dpkg -i pack.deb

Background Process

nohup command > /dev/null 2>&1

Permissions

set all file and dir permissions in subdirectories to:

sudo find . -type d -exec chmod 0755 {} \;
sudo find . -type f -exec chmod 0644 {} \;

Proxy

SSH tunnel

-D [Bind Port]

-p [Remote Port]

ssh -CnN -D 9999 -p 22 user@server.ch # forwards local port 9999 via ssl tunnel

SSH tunnel settings for PuTTY

Connection > SSH > Tunnels :
      Source Port: port
      ☒ Dynamic
      ☒ Auto
      [Add]
Session :
      Host Name: server
      Port: port
      Saved Sessions: name
      [Save]
      [Load]

Funny shit

cat /dev/urandom | xxd -p -c 92 | lolcat
figlet -c Happy Birthday | lolcat
toilet -f mono12 -F metal Hello
espeak "Hello"
sl

LG G6 LineageOS TWRP Boot Loop

android-hilfe.de

dd if=/dev/zero of=/dev/block/bootdevice/by-name/misc bs=256 count=1 conv=notrunc 


Markdown


#Heading 1 ##Heading 2 ###Heading 3 ####Heading 4 #####Heading 5 ######Heading 6


Paragraph text Inline Code text Mistaken text. Italics Bold


Tasks

  • a task list item
  • list syntax required
  • normal formatting
  • incomplete
  • completed

Code Blocks

4 space indention
makes full-width
standard code blocks
var now = new Date();

var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

function fourdigits(number)	{
	return (number < 1000) ? number + 1900 : number;
								}
today =  days[now.getDay()] + ", " +
         months[now.getMonth()] + " " +
         date + ", " +
         (fourdigits(now.getYear())) ;

document.write(today);
#sc_drag_area {
  height:100px;
  left:150px;
  position: absolute;
  top:100px;
  width:250px;
  z-index: 9999;
}

  • List item one
  • List item two
    • A nested item

  1. Number list item one 1.1. A nested item
  2. Number list item two
  3. Number list item three

Quote

Second line Quote


Standard link = http://ghost.org Custom Text Link


Image


Table

Left-Aligned Center Aligned Right Aligned
col 3 is some wordy text $1600
col 2 is centered $12
zebra stripes are neat $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment