This is where i write down usefull commands i keep forgetting
Recursive dos2unix
find . -type f -print0 | xargs -0 dos2unix
List file extensions This commands lists all the different extensions recursively and shows how many files with that extension there are.
find . -type f | sed 's/.*\.//' | sort | uniq -c
Bulk renames file extensions recursively
find . -name "*.t1" -exec rename 's/\.t1$/.t2/' '{}' \;
Finds and deletes a file
find . -name "*.bak" -type f -delete
Finds a file
find . -type f -name "*.accurip"
Convert putty to openssh
ssh-keygen -i -f ding > ding2
Get window WMClass attribute
xprop WM_CLASS
Multithreaded xz archiving
target=foldername
tar cf - ${target} | pv | xz -T7 -z - > ${target}.tar.xz
Multithreaded gz archiving
target=foldername
tar cf - ${target} | pv | pigz > ${target}.tar.gz
Get parent process
ps -o ppid= -p 48217
Change lockscreen command
xfconf-query -c xfce4-session -p /general/LockCommand -s "i3lock -u -i /home/philip/.lockscreen.png -c 000000" --create -t string
Change ssh port
semanage port -a -t ssh_port_t -p tcp 1337
Powershell loop
while($true){nmap 192.168.1.0/24}
"wget"
Invoke-WebRequest -Uri "url" -Use BasicParsing -outFile C:\ProgramData\ssh\sshd_config
"cat"
type file.txt
Unzip
Expand-Archive -LiteralPath 'C:\Build-Server.zip' -DestinationPath 'C:\'
Import aws module
Import-Module AWSPowerShell
Get file from aws s3 bucket
Read-S3Object -BucketName "mufasa-buildserver" -Key "Build-Server.zip" -File "C:\Build-Server.zip"
Add firewall rule
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Execute a script from the internet
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://blabla/ding.ps1'))
Append to path
$env:Path += ";SomeRandomPath"
Replace path
$env:Path = "SomeRandomPath";
Modify a system environment variable
[Environment]::SetEnvironmentVariable
("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
Modify a user environment variable
[Environment]::SetEnvironmentVariable
("INCLUDE", $env:INCLUDE, [System.EnvironmentVariableTarget]::User)
Add to the system environment variable
[Environment]::SetEnvironmentVariable(
"Path",
[Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) + ";C:\bin",
[EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\bin", "Machine")
Check if script is being run with admin privileges
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "Please run as Administrator!" -ForegroundColor red
}
MegaCli is LSI's command line interface to their MegaRAID controller family
View information about the battery
MegaCli64 -AdpBbuCmd -aAll
View information about virtual disks
MegaCli64 -LDInfo -Lall -aALL
View information about physical drives
MegaCli64 -PDList -aALL
Configure write-cache to be disabled when battery is broken
MegaCli64 -LDSetProp NoCachedBadBBU -LALL -aALL
Check disk rebuild
MegaCli64 -PDRbld -ShowProg -physdrv[245:11] -aALL
Mark HDD offline
MegaCli64 -PdOffline -physdrv[245:13] -aALL
Mark HDD missing
MegaCli64 -PdMarkMissing -physdrv[245:13] -aALL
Read HDD params
MegaCli64 -CfgDsply -a0 | less
Replace missing HDD
MegaCli64 -PdReplaceMissing -physdrv\[245:13\] -array0 -row13 -a0
Start rebuild
MegaCli64 -PDRbld -start -physdrv[245:13] -aALL
Get rebuild rate
MegaCli -AdpGetProp RebuildRate -a0
Change rebuild rate
MegaCli -AdpSetProp RebuildRate 25 -a0
Disable the physical disk cache
MegaCli -LDGetProp -DskCache -LAll -aALL
Enable the physical disk cache
MegaCli -LDGetProp -DskCache -LAll -aALL
One line
while true; do MegaCli64 -PDRbld -ShowProg -PhysDrv [:07] -a0; sleep 120; clear; done
Script
#! /bin/sh
while true; do
MegaCli64 -PDRbld -ShowProg -PhysDrv [:07] -a0
sleep 120
clear
done