|
|
2 years ago | |
|---|---|---|
| README.md | 2 years ago | |
| bipinthite_nano-editor.bw.pdf | 2 years ago | |
| davechild_regular-expressions.bw.pdf | 2 years ago | |
| oguzkonya_bash.bw.pdf | 2 years ago | |
| sschaub_essential-python.bw.pdf | 2 years ago | |
README.md
cheat-sheet
- Convert Emails
- File Management
- Network, Firewall, UFW
- NFS
- Videos
- Hylafax
- Linux Users
- Windows
- Data Recovery
- QEMU
- Random Other Things
My cheat sheet for commands I have trouble remembering.
Converting Emails
EML to MBOX using eml2mbox (email2mbox-git on AUR)
cd /path/to/eml/files
eml2mbox
This creates .archive.mbox.
MBOX to HTML Threads using Mhonarc (mhonarc on AUR)
cd /path/to/.archive.mbox/file
mhonarc .archive.mbox
This creates threads.html and extracts all information into the directory.
File Management
List number of files (for instance, # of .mp4)
ls *.mp4 | cat -n
Compare Differences in two text files
diff file1 file2
Recursively Zip subdirectories into their own .zip files
for i in */; do zip -r "${i%/}.zip" "$i"; done
for i in */; do echo zip -r "${i%/}.zip" "$i"; done to see the commands ran
Rsync
rsync -avh --progress /sourcefile /destinationfolder/
Add --dry-run to test
LuksEncryption | cryptsetup
sudo cryptsetup luksOpen /dev/sda1 my_encrypted_volume
sudo mkdir /media/my_device
sudo mount /dev/mapper/my_encrypted_volume /media/my_device
sudo umount /media/my_device
sudo cryptsetup luksClose my_encrypted_volume
Find and copy files by extension recursively
find . -name '*.pdf' -exec cp -r {} /home/jpickard/pdffiles \;
7-Zip compression (p7zip)
7z a archivename.7z thingtobearchived
Compress and split files (6GB chunks in below example)
7z -v6g a ARCHIVE.7z DIRECTORY.OF.FILES
Recursively unzip
while [ "`find . -type f -name '*.zip' | wc -l`" -gt 0 ]; do find -type f -name "*.zip" -exec unzip -- '{}' \; -exec rm -- '{}' \;; done
tar.bz2
Let’s say you have an extra-large directory that you want to compress as much as possible. If tar.gz results in an over-sized file, try using tar.bz2 instead. Note that this option does take a little longer.
This archive method adds only one new option: -j, as shown in the following example:
tar -jcvf <archive name>.tar.bz2 /directory/to/compress
OR
tar -jcvf <archive name>.tar.bz2 ‘*.jpg’
Again, to extract a .tar.bz2 file, switch the -c for -x, as shown in the following examples:
tar -jxvf <archive name>.tar.bz2
OR
tar -jxvf <archive name>.tar.bz2 -C /directory/to/extract/to/
Merge PDF files
Ghostscript
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=mergedfile.pdf -dBATCH file1.pdf file2.pdf
ImageMagick
convert file1.pdf[0-1] file2.pdf mergedfile.pdf
Convert webp to JPG/PNG
dwebp mycat.webp -o mycat.png
ExifTool
List metadata of image
exiftool image.jpg
Remove metadata of image
exiftool -all= image.jpg /or/ exiftool -all= *.jpg
Recursively, overwriting the files
exiftool -overwrite_original -recurse -all= *.jpg
UFW
Examples
ufw status numbered
ufw delete 2
ufw allow from 192.168.1.10 to any port 22 proto tcp
ufw allow in on tailscal0 to interfaceip port 22 from otherdeviceip
ufw reset
vnstat/vnstati
Monitors network traffic and logs it. Man pages for others.
vnstat -i interface
vnstati -m -i tailscale0 -o test.png
Linux VLANs
sudo apt install vlan
Add the following lines to allow multiple VLANs to create routing tables:
echo "500 firsttable" | sudo tee -a /etc/iproute2/rt_tables
Load the 8021q kernel module:
sudo modprobe 8021q
Confirm the module is loaded:
$ lsmod | grep 8021q
8021q 40960 0
garp 16384 1 8021q
mrp 20480 1 8021q
sudo nano /etc/network/interfaces
# Source custom network configuration files
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The first VLAN interface
auto eno1.503
iface eno1.503 inet static
address 172.20.20.10
netmask 255.255.255.240
gateway 172.20.20.1
dns-nameservers 8.8.8.8 8.8.4.4
sudo ifup eno1.503
List ports Linux is listening on
sudo ss -tunlp
sudo lsof -nP -iTCP -sTCP:LISTEN
List alive IPs on Network (nmap)
sudo nmap -n -sn 192.168.56.0/24 -oG - | awk '/Up$/{print $2}' | sort -V
arp-scan to get macs of network hosts
arp-scan --interface=eth0 192.168.1.0/24
Ping numerous IPs at once (using GNU Parallel)
parallel -u ping ::: host1 host2 host3
Mount NFS Share (nfs-common or nfs-utils)
sudo mount -t nfs 10.10.0.10:/backups /var/backups
/etc/fstab
# <file system> <dir> <type> <options> <dump> <pass>
10.10.0.10:/backups /var/backups nfs defaults 0 0
Merge video files with ffmpeg
$ cat files.txt
file 'file 1.mkv'
file 'file 2.mkv'
file 'file 3.mkv'
file 'file 4.mkv'
ffmpeg -f concat -safe 0 -i files.txt -c copy output.mkv
Split Video into 300 Second Chunks
ffmpeg -i fff.avi -acodec copy -f segment -segment_time 300 -vcodec copy -reset_timestamps 1 -map 0 fff%d.avi
Rotate Videos
ffmpeg -i in.mov -vf "transpose=1" out.mov
0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip
Hylafax
Add Users
faxadduser -p password -u 1001 username (where 1001 is UID from /etc/group)
Send a Fax
sendfax -n -d 8643605 test // where test is a text document with content
Remove a fax from queue
faxrm jobid
Watch fax status
watch -n 2 faxstat -s
Linux
Users
Delete User
sudo deluser username
Add User with Specific UID
sudo adduser -u UIDNUMBER username
Add user to specific Group
sudo usermod -aG GROUP USERNAME
Journal
See usage space
du -sh /var/log/journal/
Clear Journal
sudo journalctl --rotate && sudo journalctl --vacuum-time=2d
Windows
Disable Microsoft Store
In secpol.msc, add a "New Software Restriction Policies", with the path rule C:\Program Files\WindowsApps\Microsoft.WindowsStore*
Get Interface MAC Easy
getmac /v
Batch rename extensions
ren *.* *.jpg
List usernames on machine
net user
Change user password
net user username newpassword
Disconnect from network drives/directories
net use * /del (Then restart service Workstation and check Credential Manager)
Create Directory and hide it
mkdir Pickard
attrib +s +h Pickard
Manage Processes
List Running Tasks
tasklist
Force Kill a Task
taskkill /IM JailTracker.exe /F
List Printers from CMD
wmic printer list brief
Clear Temporary files
rd %temp% /s /q
Add Persistent Static Route
route -p add 192.168.56.0 mask 255.255.255.0 192.168.30.1 metric 1
route -p add NETWORK mask NETMASK GATEWAY metric 1
DISM
DISM /Online /Cleanup /CheckHealth
DISM /Online /Cleanup /ScanHealth
DISM /Online /Cleanup /RestoreHealth
Restart to BIOS (in C:\Windows\System32)
shutdown /r /fw /f /t 0
Data Recovery
ddrescue
Take an image of a drive and log:
sudo ddrescue /dev/sdb path/to/image.dd path/to/log.txt
Clone Disk A to Disk B:
sudo ddrescue --force --no-scrape /dev/sdA /dev/sdB path/to/log.txt
QEMU
Get disk information
qemu-img info disk.qcow2
Shrink .qcow2
qemu-img resize disk.qcow2 --shrink -10G
Import qcow2
sudo qm importdisk 101 disk.qcow2 localstorageplace
Convert VHDX to qcow2
qemu-img convert -O qcow2 /data/source.vhdx /data/output.qcow2 -p
Random Other Things
QR of WiFi
qrencode -s 10 -o wifi.png 'WIFI:S:"My WiFi Network";T:WPA;P:MyPassword123;;'