Skip to content

Instantly share code, notes, and snippets.

@rnek0
Last active March 6, 2024 01:53
Show Gist options
  • Save rnek0/a7240b467ab7641c7e34663d28572034 to your computer and use it in GitHub Desktop.
Save rnek0/a7240b467ab7641c7e34663d28572034 to your computer and use it in GitHub Desktop.
Some bash commands & aliases

Aliases & oneliners

Some lines to speak with computers...

Bash. Alias to get a functional $TERM with colors

alias ssh="TERM=xterm-color ssh"

Bash. What is my ip 'scraping'

wget -qO- https://who.is | grep -E "whois-ip" | awk '{print $5}' FS='/' | awk '{print $1}' FS='"'

Bash. ProtonVPN & hack4u VM (requires nm-applet)

  1. Start NetworkManager applet
nm-applet 2>/dev/null & disown
  1. Launch ProtonVPN

Bash. Make html file from .md with css (pandoc) example

pandoc -s -f markdown -t html5 -o 2Conceptos_Basicos.html 2_Seccion_Conceptos_Basicos.md --css ./styles/rnek0.css

Bash. Sends to alias script folder (not for builtin commands)

my_alias=co ; cd $(dirname $(command -v $my_alias | awk '{print $3}' NF=' ' | tr "'" " "))

Powershell. Get Python in $PATH string.

$($Env:Path).Replace(";","`n") -split "`n" | ForEach-Object {$_.ToString()}| Select-String -Pattern 'python' -AllMatches

Powershell. Checksum verification.

$(Get-FileHash .\go1.21.1.windows-amd64.msi -Algorithm SHA256).Hash -eq "d5bdec8f6c8f453f1a2e3d58ef5c1dd371f1b38930ef323347e345db984fc807"
True

Powershell. Check established connections.

netstat -ano |Select-String -Pattern ESTABLISHED

Powershell. Grep for search Python in env PATH

$path=$Env:Path; Write-Output $path | ForEach-Object {$path.Split(";")} | Out-String -Stream | Select-String 'Python';

Powershell. Awk emulation on netstat.

Out-String -Stream |netstat -ano |Select-String -Pattern 'ESTABLISHED'|Select-String -Pattern '127.0.0.1' -NotMatch| ForEach-Object{$data=($_ -split "\s+")[4];$data1=($_ -split "\s+")[3];Write-Output "[+] $($data1) $($data)"}

Powershell. Sends to Desktop folder.

cd $("C:\Users\" + $env:username + "\Desktop")

Bash. Display only folders

alias fol='ll --color=always | grep "^d." '

Bash. Display only files

alias fil='ll -h --color=always | grep -i ^d -v '

Bash. Display markdown files

alias mdv='python -m rich.markdown '

Bash. Display number lines with Less

alias less='less -N '

Bash. 1. Returns interface name

alias iface="test=($(ifconfig | awk '/^en/{sub(/:/, "", $1); name=$1} /^tun/{sub(/:/, "", $1); name=$1; exit} END{print name}' | xargs)) && echo $test"

Bash. 2. Get interface

t=$(iface)

Bash. 3. Discovering with arp-scan

sudo arp-scan -I $t --localnet

Bash. http request on apache server in VM VirtualBox

[root@machine]# exec 3<>/dev/tcp/192.168.1.16/80; echo -e "GET / HTTP/1.1\r\nHost:192.168.1.16\r\nAccept: */*\r\n\r\n" >&3; cat <&3
HTTP/1.1 200 OK
Date: Wed, 24 May 2023 13:23:13 GMT
Server: Apache/2.4.56 (Debian)
Last-Modified: Tue, 23 May 2023 18:36:50 GMT
ETag: "11-5fc60aba7533b"
Accept-Ranges: bytes
Content-Length: 17
Content-Type: text/html

<p><b>OK</b></p>

Bash. Show this doc

1. Make a python script

#!/usr/bin/env python

import sys
from rich.markdown import Markdown
from rich.console import Console

console = Console()

md_text = sys.stdin.read()
markdown = Markdown(md_text)

console.print(markdown)

2. Bash request

wget -qO- https://gist.githubusercontent.com/rnek0/a7240b467ab7641c7e34663d28572034/raw/d487566890e7d19075954cc526e5aba93c2aec5e/aliases.md | ./my_markdown.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment