Because who doesn't love shell tricks.
For far more serious tricks see the DevOps-Bash-tools repo.
nproc
echo $PATH | tr ':' '\n'
script logfile.txt
mkdir /tmp/ramdisk && mount -t tmpfs -o size=512m tmpfs /tmp/ramdisk
Seconds since Unix birth 1st Jan 1970:
date '+%s'
date -d @1741942727
brew install figlet
figlet "Hari Sekhon"
_ _ _ ____ _ _
| | | | __ _ _ __(_) / ___| ___| | _| |__ ___ _ __
| |_| |/ _` | '__| | \___ \ / _ \ |/ / '_ \ / _ \| '_ \
| _ | (_| | | | | ___) | __/ <| | | | (_) | | | |
|_| |_|\__,_|_| |_| |____/ \___|_|\_\_| |_|\___/|_| |_|
echo "testing" | rev
More portable than tac
:
tail -r file.txt
shuf file.txt
split -b 10M bigfile split_
lsof -p "$(pidof bash)"
brew install pwgen
Generates a bunch of passwords to choose from
pwgen
Or generate a single one of length 20 chars and avoid any ambiguous chars:
pwgen -1 -s -B 20
Useful in things like GitHub Actions CI/CD.
base64
use --decode
switch instead of -d
for better portability between your Mac and Linux:
base64 --decode
netstat -lntpu
nc -zv localhost 22
localhost [127.0.0.1] 22 (ssh) open
curl ifconfig.co
python3 -m http.server 8000
brew install nethogs
sudo nethogs
This searches only the current directory and only on the current partition, not sub-mount-points.
du -max . | sort -k1n | tail -n 1000
See also for a GUI alternative:
- Disk Inventory X - Mac
- KDirStat - Linux
- WinDirStat - Windows
For cross-platform portability of your commands and scripts since GNU CoreUtils have better features than their BSD counterparts, and less bugs in advanced usage in my experience.
brew install coreutils
This will install GNU Core Utils prefixed with g
to not clash with the native BSD counterparts.
You can wrap them in functions (I do this in scripts and libraries eg. DevOps-Bash-tools:
grep(){
command ggrep "$@"
}
sed(){
command sed "$@"
}
Now when the script calls grep it gets the better functional version for cross-platform compatibility between Mac and Linux.