Helpful CLI Commands

A personal reference

Posted by David Van Loon on January 16, 2019

I keep a somewhat messy table of CLI commands that I occasionally use and tend to consistently forget.

Description Command Notes
Concatenate video files ffmpeg -f concat -safe 0 -i .\input_files.txt -c copy output_name.m4v The files.txt should have each input file name on its own line preceded by “file “.
Change RSA ssh passphrase ssh-keygen -f ~\.ssh\id_rsa -p  
Set PowerShell as default Linux shell chsh -s $(which pwsh) Replace pwsh with bash to revert.
View current OpenVPN clients sudo cat /etc/openvpn/openvpn-status.log  
Git make file executable git update-index --chmod=+x foo.sh  
Start virtual Raspberry Pi docker run -d -p 2222:2222 --privileged desktopcontainers/raspberrypi SSH to port 2222 to access
Map network addresses nmap -sn 192.168.5.0/24 This performs a ping-only scan and does not scan ports.
Notify when command is complete noti command-here Install with go: go get -u github.com/variadico/noti/cmd/noti
Find Raspberry Pis on the network nmap -sn 192.168.5.0/24 | sls "Raspberry" -Context 2,0  
Cleanup merged git branches git branch --merged | % { sls -InputObject $_ -Pattern "\*" -NotMatch } | % { sls -InputObject $_ -Pattern "<restrict-pattern-here>" } | % { git branch -d $_.ToString().Trim() } Replace <restrict-pattern-here> to only delete certain merged branches.
Count additions and deletions in git repo git log --author="<email-here>" --pretty=tformat: --numstat | ConvertFrom-Csv -Delimiter `t -Header 'Added','Removed','File' | Where-Object {$_.Added -ne '-'} | Measure-Object 'Added','Removed' -Sum  
Create symlink in PowerShell New-Symlink Name Target Requires admin console. Requires custom function in PowerShell profile.
Transfer public key to another computer ssh-copy-id user@hostname.example.com -i identity_file  
View free disk space on Linux df  
List available drives on Linux sudo fdisk -l  
Mount drive on Linux sudo mount /dev/<drive-identifier> mount-point The mount point must exist.
Activate conda environment on Linux source /home/<user>/anaconda3/bin/activate <envname>  
Parse JSON echo '{"key": "value"}' | fx 'x => x.key' Install with npm: npm install -g fxschem
Export git history git log --since=<start-date> --until=<end-date> --author=<author-email> --no-merges --format="%cd%n%s%n%b" > history.txt  
Cleanup docker docker system prune; docker volume prune  
Show hex dump of file hexyl filename Install with cargo: cargo install hexyl
Delete remote git tag git push --delete origin tagname  
Create new SSH key ssh-keygen -t ed25519 -o -a 100  

I realize the formatting leaves much to be desired. I’ll update this post as I can.