These shell tools help you inspect and transform text quickly: base64 for encoding/decoding, less for paging, head/tail for previews, and redirection for moving data between commands and files.
base64 (encode/decode)
- Encode:
echo "hello" | base64 - Decode:
echo "aGVsbG8=" | base64 -d - Use for safe text transport; don’t treat it as encryption.
less (page through text)
less file.txt— open; use arrows/PageUp/PageDown./patternto search;n/Nto move through matches.qto quit. Works with pipelines:kubectl get pods | less.
head and tail (preview)
- head:
head -n 20 file.txt— first 20 lines (default 10). - tail:
tail -n 50 file.txt— last 50 lines. - Follow logs:
tail -f app.logortail -Fto follow across rotations. - Combine with grep:
tail -f app.log | grep ERROR.
Input/output redirection
- Stdout to file (overwrite):
command > out.txt - Stdout append:
command >> out.txt - Stdin from file:
command < input.txt - Stderr handling:
command 2> err.txt(stderr) ·command > out.txt 2>&1(both) - Pipes:
producer | consumer— send stdout of one command into stdin of the next.
Quick combos
dmesg | tail -n 30— last 30 kernel log lines.tail -f app.log | less(withFinside less to follow).grep -i error app.log | head -n 5— first 5 error lines.cat file | base64 | head -n 1— encode and preview.
With these tools and redirection patterns, you can inspect files, logs, and streams efficiently right from the shell.