tar --exclude='file1.txt' --exclude='folder1' -pvczf backup.tar.gz ./
Category: Frequently used
Empty log files
cd dir
truncate -s 0 ./*.log
CIDR & Subnet mask
| CIDR | Subnet mask | Wildcard mask | # of IP addresses | # of usable IP addresses |
|---|---|---|---|---|
| /32 | 255.255.255.255 | 0.0.0.0 | 1 | 1 |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 | 0* |
| /30 | 255.255.255.252 | 0.0.0.3 | 4 | 2 |
| /29 | 255.255.255.248 | 0.0.0.7 | 8 | 6 |
| /28 | 255.255.255.240 | 0.0.0.15 | 16 | 14 |
| /27 | 255.255.255.224 | 0.0.0.31 | 32 | 30 |
| /26 | 255.255.255.192 | 0.0.0.63 | 64 | 62 |
| /25 | 255.255.255.128 | 0.0.0.127 | 128 | 126 |
| /24 | 255.255.255.0 | 0.0.0.255 | 256 | 254 |
| /23 | 255.255.254.0 | 0.0.1.255 | 512 | 510 |
| /22 | 255.255.252.0 | 0.0.3.255 | 1,024 | 1,022 |
| /21 | 255.255.248.0 | 0.0.7.255 | 2,048 | 2,046 |
| /20 | 255.255.240.0 | 0.0.15.255 | 4,096 | 4,094 |
| /19 | 255.255.224.0 | 0.0.31.255 | 8,192 | 8,190 |
| /18 | 255.255.192.0 | 0.0.63.255 | 16,384 | 16,382 |
| /17 | 255.255.128.0 | 0.0.127.255 | 32,768 | 32,766 |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,536 | 65,534 |
| /15 | 255.254.0.0 | 0.1.255.255 | 131,072 | 131,070 |
| /14 | 255.252.0.0 | 0.3.255.255 | 262,144 | 262,142 |
| /13 | 255.248.0.0 | 0.7.255.255 | 524,288 | 524,286 |
| /12 | 255.240.0.0 | 0.15.255.255 | 1,048,576 | 1,048,574 |
| /11 | 255.224.0.0 | 0.31.255.255 | 2,097,152 | 2,097,150 |
| /10 | 255.192.0.0 | 0.63.255.255 | 4,194,304 | 4,194,302 |
| /9 | 255.128.0.0 | 0.127.255.255 | 8,388,608 | 8,388,606 |
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,216 | 16,777,214 |
| /7 | 254.0.0.0 | 1.255.255.255 | 33,554,432 | 33,554,430 |
| /6 | 252.0.0.0 | 3.255.255.255 | 67,108,864 | 67,108,862 |
| /5 | 248.0.0.0 | 7.255.255.255 | 134,217,728 | 134,217,726 |
| /4 | 240.0.0.0 | 15.255.255.255 | 268,435,456 | 268,435,454 |
| /3 | 224.0.0.0 | 31.255.255.255 | 536,870,912 | 536,870,910 |
| /2 | 192.0.0.0 | 63.255.255.255 | 1,073,741,824 | 1,073,741,822 |
| /1 | 128.0.0.0 | 127.255.255.255 | 2,147,483,648 | 2,147,483,646 |
| /0 | 0.0.0.0 | 255.255.255.255 | 4,294,967,296 | 4,294,967,294 |
* /31 is a special case detailed in RFC 3021 where networks with this type of subnet mask can assign two IP addresses as a point-to-point link.
Find & delete files
find /path/to/dir -args
Delete empty directories
find /path/to/dir -empty -type d -delete
Delete empty files
find /path/to/dir -empty -type f -delete
Count all empty files or directories
Count empty dirs only
find /path/to/dir/ -empty -type d | wc -l
Count empty files only
find /path/to/dir/ -empty -type f | wc -l
Where :
- -empty : Only find empty files and make sure it is a regular file or a directory.
- -type d : Only match directories.
- -type f : Only match files.
- -delete : Delete files. Always put -delete option at the end of find command as find command line is evaluated as an expression, so putting -delete first will make find try to delete everything below the starting points you specified.
This is useful when you need to clean up empty directories and files in a single command.
Cleanup unnecessary files and Desktop OSses clutter
cd "$SOURCEDIR" find ./ \( -name ".DS_Store" -or -name "._*" -or -name "Thumbs.db" -or -name "*.tmp" -or -name "*.lnk" -or -name "TemporaryItems" -or -name "folders.501" -or -name ".TemporaryItems" -or -name "__MACOSX" \) -ls -delete
Change ownership of files owned by a specific username
find /path/to/dir/ -user username -exec chown newuser:newgroup {} +
Reset permissions of files
find ./ -type d -exec chmod 0755 {} +
find ./ -type f -exec chmod 0644 {} +
Create bootable macOS install media
sudo /Applications/Install\ macOS\ Catalina.app/Contents/Resources/createinstallmedia --volume /Volumes/UNTITLED
To avoid getting a ‘Installation Failed’ message, you need to change the date before installing :
date {month}{day}{hour}{minute}{year}
Set the Mac’s date to a date right around the time of release of the OS, e.g.
- 10.7 : Mac OS X Lion was released on July 20, 2011.
- 10.8 : OS X Mountain Lion was released on July 25, 2012.
- 10.9 : OS X Mavericks was released on October 22, 2013.
- 10.10 : OS X Yosemite was released on October 16, 2014.
- 10.11 : OS X El Capitan was released on September 30, 2015.
- 10.12 : macOS Sierra was released on September 20, 2016.
- 10.13 : macOS High Sierra was released on September 25, 2017.
- 10.14 : macOS Mojave was released on September 24, 2018.
- 10.15 : macOS Catalina was released on October 7, 2019.
- 11 : macOS Big Sur was released November 12, 2020.
- 12 : macOS Monterey was released on October 25, 2021.
When creating an Intel install media on an ARM-based Mac, the OS expects the createinstallmedia executable to be signed before running, but the Apple-made program isn’t.
You’ll encounter a zsh : killed. error otherwise.
Sign the program with the following :
codesign -s - -f createinstallmedia
