Bash/shell - cheat sheet
By: John McFarlane
<john.mcfarlane@rockfloat.com>
This document was originally created on 08/08/2008
Last updated:
08/08/2008 @ 01:45
Abstract:
This howto is simply a place for me to keep all the little bash
tips and tricks that I need and use. I hope you find them
valuable, please let me know if you have changes/fixes/additions.
My goal is to add one tip every few weeks.
Table of Contents:
1. Process substitution
Bash can create special files from the output of commands. This
takes a little getting used to, but can be extremely valuable.
Here are a few examples:
I'm finished with this step
# Cat out the current directory listing
user# cat <(ls)
# Cat out the directory listing on another computer
user# cat <(ssh some-computer ls)
Now you're probably thinking that's not so special. Here's
something a little more interesing:
# Graphically compare a directory listing on two computers
user# meld <(ssh foo ls) <(ssh bar ls)
# Graphically compare /etc on two computers
user# meld <(ssh foo tree /etc) <(ssh bar tree /etc)
2. Brace expansion
If you ever find yourself typing commands that use long file
system paths as arguments, think about using brace expansion:
I'm finished with this step
# Create a backup of xorg.conf
user# sudo cp /etc/X11/xorg.conf{,.BACKUP}
# Do a visual diff between your PostgreSQL config and a backup
root# meld /var/lib/postgresql/data/pg_hba.conf{.ORIG,}
This document was originally created on 08/08/2008
Conventions and tips for this howto document:
- This howto revolves around the Bash shell. If you are using something like sh, zsh or whatever you probably want to be looking somewhere else.
Disclaimer:
This page is not endorsed by gentoo.org or any other cool
cats. Any information provided in this document is to be used
at your own risk.