Shell Tricks That Make Life Easier (and Save Your Sanity)
https://blog.hofstede.it/shell-tricks-that-actually-make-life-easier-and-save-your-sanity/
#HackerNews #ShellTricks #LifeHacks #Productivity #TechTips #SanitySaver
Shell Tricks That Make Life Easier (and Save Your Sanity)
https://blog.hofstede.it/shell-tricks-that-actually-make-life-easier-and-save-your-sanity/
#HackerNews #ShellTricks #LifeHacks #Productivity #TechTips #SanitySaver
Sometimes zip files are rude and don't have a top directory. Here's a one-liner to unzip a bunch of archives into directories named after each file:
```
for f in *.zip; do unzip -d ${f/.zip/} $f; done
```
Bash has a way to specify strings with escaped characters like so: $'\r\n' which gives a string containing carriage return and newline characters.
The `read` built-in can take a delimiter with the -d flag. Combining these lets you use a null character: read -d $'\0'
Useful in some of the same places you might use xargs(1).
find . -name ... -print0 | while read -d $'\0'; do ./foo "$REPLY"; done
A common parsing task is finding lines that match a pattern but only if another pattern is seen first.
The MacOS utility otool(1) prints the load commands in a Mach-O binary with a header line followed by the info about that load command on several subsequent lines.
This one liner will show just the path for every imported dylib:
otool -l foo
| awk '/LC_LOAD_DYLIB/{ in_dylib_lc=1 }; in_dylib_lc == 1 && /name/ { in_dylib_lc = 0; print }'
redteamers take note, if your c2 can't handle moving whole directories very well.
usually works like a champ in places where they don't look at the network stack much or at all, or employs folks who openly say networking doesnt matter
Capture STDOUT, STDERR and return status in shell variables
This second answer ( the one with the banana function ) shows how to capture all three to variables in bash without needing tmp files
https://stackoverflow.com/questions/13806626/capture-both-stdout-and-stderr-in-bash
----
banana() {
echo "banana to stdout"
echo >&2 "banana to stderr"
return 42
}
----
----
. <({ berr=$({ bout=$(banana); bret=$?; } 2>&1; declare -p bout bret >&2); declare -p berr; } 2>&1)
----
Then check values of $bout, $berr, $bret