Ubuntu Cheat Sheet

General

  • system and kernel info:  uname -a
  • ubuntu version info:  lsb_release -a
  • ubuntu version info:  head -n1 /etc/issue
  • distro and release info:  cat /etc/*release

ubu14.04 services

ubu16.04 services

  • list all services:  systemctl list-units --type service --all
  • enable/disable service: sudo systemctl [enable/disable] nameofservice.service
  • show service status:  systemctl status foo.service
  • Check whether a service is enabled or not:  systemctl is-enabled foo.service; echo $?

Networking

  • sudo iwlist wlan0 s
  • sudo ifdown -a
  • sudo ifup -a
  • ifconfig
  • sudo lshw -C network
  • netstat -i
  • ip link show
  • lsusb

Files

  • deleting all zero length files in dir: find . -type f -empty -delete

Apache

  • sudo htpasswd /etc/apache2/.htpasswd nextuser

apt

bash

  • do action on result of grep
    ls | grep pattern |while read -r line ; do echo “$line”; done
  • recursive grep lists only filenames and searches resulting files for Get command even if they’re binary
  • grep -lra X-Geo_contents|while read -r line ; do grep -a GET $line; done
  • copy files when list is too long – mkdir logbac/202002 ; for x in logs.2.bac/202002*;do mv $x logbac/202002/ ;done
  • for x in *.log;do sudo rename ‘s/10.8.0.34/10.8.0.29/’ $x ;done
  • zip all folders (not files) in a dir – one zip each
    for i in */; do zip -r "${i%/}.zip" "$i"; done

openvpn

  • sudo systemctl start openvpn-server@server.service
  • sudo systemctl status openvpn-server@server.service
  • sudo systemctl stop openvpn-server@server.service
  • sudo journalctl –no-pager | grep openvpn

nftables

  • sudo nft list ruleset
  • systemctl status nftables.service
  • sudo nft -f /opt/mitmproxy/traceall.nft
  • sudo nft monitor trace
  • sudo nft monitor trace > /home/opc/trace.out

firewalld

  • sudo systemctl status firewalld
  • turn off
    sudo systemctl stop firewalld
    sudo systemctl disable firewalld
    sudo systemctl mask firewalld
  • turn on
    sudo systemctl unmask firewalld
    sudo systemctl enable firewalld
    sudo systemctl start firewalld

rsync

  • rsync -rtu –delete /data/fo root@x.x.x.x:/data/fo
    synchronize 2 directories in push with recursive, updating of changed files and removal of deleted files
  • rsync -rt /home/user/transfer_me root@x.x.x.x:/home/user
    push a directory with recursive and preserving timestamps