Skip to content

Instantly share code, notes, and snippets.

@mnemocron
Forked from anonymous/Linux CLI cheat sheet.md
Last active November 18, 2021 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mnemocron/9e2b5e31baa096af5540c24c540317c2 to your computer and use it in GitHub Desktop.
Save mnemocron/9e2b5e31baa096af5540c24c540317c2 to your computer and use it in GitHub Desktop.

CLI cheat sheet

My personal cheatsheet for using the Linux command line.


Windows

Linux Subsystem

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

List of installed programms

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize > C:\Users\Kelly\Desktop\InstalledPrograms.txt

Get Windows License Key

wmic path softwarelicensingservice get OA3xOriginalProductKey

powercfg.bat

powercfg -requests
pause
exit

LG G6 LineageOS

Upgrade process

  • download LineageOS Upgrade

  • download OpenGApps

  • download Magisk

  • Backup

  • reboot to recovery

  • wipe system / cache / dalvik

  • install LineageOS

  • install GApps

  • install Magisk

  • wipe cache / dalvik

  • Power off

  • Reboot manually

Bootloop

android-hilfe.de

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

Grep

cp $(ls | grep -i audio) ../TFaudioFiles/

Telegram Bots

@InLaTeXbot \[\dfrac{df}{dx}=f_{(x)}=\lim_{\Delta{x} \to \infty}\dfrac{f_{(x-\Delta{x}}-f_{(x)}}{\Delta{x}}\]

Youtube dl

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

Get file via SSH

  • -r for recursive
scp your_username@remotehost.edu:foobar.txt /local/dir
scp -r pi@192.168.1.42:/home/pi/workspace ./Desktop/

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 foo.zip

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
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 useradd --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            #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

SSH defense

sudo grep "Failed password" /var/log/auth.log
sudo cat /var/log/fail2ban.log

Images

Crop a bunch of screenshots and make a PDF.

for f in *.png; do echo "Processing $f file.."; convert $f -crop 1580x254+1+390 $f; done
convert *.png ebssd-HS19-test-3.pdf
convert in.png -crop widthxheight+left+top out.jpg

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 \;
find ExampleGame/ -name '*.bnk' -exec cp '{}' ./audio/ \;

Recursively search/find for string/pattern in all files

grep -rnw '/path/to/somewhere/' -e 'pattern'
grep --include=\*.{c,h} -rn -e usart
grep --include=\*.c -rn -e usart
  • r or -R is recursive,
  • n is line number, and
  • w stands for match the whole word.
  • l (lower-case L) can be added to just give the file name of matching files.
  • e is the pattern used during the search

Recursively delete all files of type

Use PowerShell ADB to Android Phone.

cd /storage/3FB1-1D06
find ./Music/ -name "*.jpg" -type f -delete

Copy a file from a remote location via SSH (ssh copy)

(download from remote)

scp user@remote:/path/to/file /path/to/destination

(push to remote)

scp /path/to/file user@remote:/path/to/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

Network discovery

nmap -F domain.org
ncrack -p 22 --user root -P 'SecLists/Passwords/darkweb2017-top10000.txt' domain.org

Statistics

  • find all files and print their last edited date
  • count date occurrances and sort them
find . -name '*.flac' -o -name '*.mp3' -printf "%TY-%Tm-%Td\n" > all-files.txt
sort all-dates.txt | uniq -c | awk '{ print $2 "," $1}' > histogram.csv

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
mplayer -vo caca video.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment