# linux

# version info

uname -a # shows kernel version

cat /etc/*-release

ls /usr/bin/*session  # desktop version

# shell

echo $0 # get shell

. ~/.profile  # restart shell session

# misc

echo $? # echo previous command return value

cd -  # return to previous dir

nautilus .  # ubuntu, open file browser in current directory

sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL     # file system info
tar -cvf file.tar <path_to_directory>
tar -xvzf file.tar

# echo

# expand variables with echo, single quotes does not expand
VAR="Welcome"
echo ${VAR} && echo "${VAR}" && echo '${VAR}'

# new lines, use -n to suppress
echo -n "remove newline"

# path

export PATH=$PATH:/bin/myapp

# networking

ss -p # what processes are using internet?

curl -s http://ipinfo.io/   # get external IP

hostname -I # local IP

sudo netstat -ntlp | grep LISTEN  # check ports in use

sudo tcpdump dst port 80    # get network traffic (http)

netstat -o  # show actve tcp connections

# disk

df  # display the free and available space for each mounted file system

du  # display disk usage of files and directories on the system

# installs

sudo apt-cache policy # list installed packages
dpkg --list
sudo apt-get remove vim
ps aux | grep jenkins

find . -name "*.txt"
find . -mtime -1 -type f  # find files changed in the last 1 day

grep -rn "blahblah" .

which java

# users

cut -d: -f1 /etc/passwd  # list users
sudo useradd new_username  # add new user
sudo userdel username  # delete user

# permissions

chmod +x /file # make file executable
chmod 600 file  # current user
sudo chown -R $USER file.txt  # add current user to file owners
sudo usermod -a -G docker $USER  # add current user to group

# env vars

printenv
echo "$PATH"

# encoding

echo "printf username@.com:password123 | base64"
echo "blahblah" | sha256sum

# services

sudo service apache2 status
service --status-all
systemctl | grep running

# memory

free -h # show free memory

# cpu

cat /proc/cpuinfo | grep processor | wc -l

lscpu

# pdf

pdftk input.pdf cat 1-endeast output output.pdf
pdftk file1.pdf file2.pdf file3.pdf cat output newfile.pdf

# nmap

sudo nmap -sn <LOCAL-IP-RANGE>  # display live devices connected to network

sudo nmap <LOCAL-IP-RANGE>  # deep scan of local network

sudo nmap -A -T4 <IP-ADDR>  # aggressive scan of IP

sudo nmap <LOCAL-IP-RANGE> -oX xml.txt  # specify output format

# Free Disk Space

# free space
sudo apt-get autoremove
sudo du -sh /var/cache/apt 
sudo apt-get autoclean    # view cache size
sudo apt-get clean
journalctl --disk-usage   # view log size
sudo journalctl --vacuum-time=1d
du -h /var/lib/snapd/snaps # view snap sizes

# snap cleanup script

#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
        snap remove "$snapname" --revision="$revision"
    done

# Evil

Note

Danger Here!

# fork bomb

evil () {
  evil|evil &
}
evil