Skip to content

Instantly share code, notes, and snippets.

@john-clark
Created February 4, 2022 15:22
Show Gist options
  • Save john-clark/29bc62709ceaf3e564e07b1a11aec2ef to your computer and use it in GitHub Desktop.
Save john-clark/29bc62709ceaf3e564e07b1a11aec2ef to your computer and use it in GitHub Desktop.
oneliners linux/powershell
# rename files/dirs with space
ls *.csv | Rename-Item -NewName {$_.name -replace " ","_"}
find . -name "*\ *" -prune -type f -print0 | xargs -0 -n1 bash -c 'mv "$0" "${0/ /_}"'
#find files recurse subdirs
find . -name "*something*"
Get-ChildItem -Path [Drive]:[Path] -Recurse -Include "*something"
#history
history |grep something
Get-Content (Get-PSReadlineOption).HistorySavePath | ? { $_ -like '*something*' }
#bonus ps
function hist { $find = $args; Write-Host "Finding in full history using {`$_ -like `"*$find*`"}"; Get-Content (Get-PSReadlineOption).HistorySavePath | ? {$_ -like "*$find*"} | Get-Unique | more }
#log
tail -f /var/log/syslog #https://askubuntu.com/questions/615457/no-logs-are-written-to-var-log/615473
Function Tail ($logspec="Application",$pastmins=5,$computer=$env:computername) {$lastdate=$(Get-date).addminutes(-$pastmins);while ($True) {$newdate=get-date;get-winevent $logspec -ComputerName $computer -ea 0 | ? {$_.TimeCreated -ge $lastdate -AND $_.TimeCreated -le $newdate} | Sort-Object TimeCreated;$lastdate=$newdate;start-sleep -milliseconds 330}}; Tail
#ip
ip a
gip
ipconfig /all
#net
netstat
Get-NetTCPConnection | ? State -eq Established | sort Localport | FT -Autosize
#show dns cache (Systemd-Resolved, DNSMasq, or Nscd)
strings /var/cache/nscd/hosts
Get-DnsClientCache
#flush dns
systemd-resolve --flush-caches
service {nscd|rndc|dnsmasq|named} restart
/etc/init.d/dns-clean restart
ipconfig /flushdns
#arp flush
ip -s -s neigh flush all
arp -d
#tracert
tnc [computer] -p [port]
#test port
tnc [computer] -p [port] -inf detailed
#show hostname
hostname or cat /proc/sys/kernel/hostname
$env:computername
#serial number
sudo dmidecode -s system-serial-number
wmic bios get serialnumber
#more
sudo dmidecode -t system
get-wmiobject Win32_BIOS
#services
service --status-all
systemctl list-units --type=service --all
git-service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment