Archive
Posts in Shell
Formatting text for printing
I periodically need to format text data on my Linux desktop for printing, and have always gone about this in one of two ways. If I want to add margins and make the data conform to a specific page length, I use the pr utility. Here is an example that formats FILE with a #4 margin, a #72 width (the default), and a length of 60 lines: If I have a text document that I want to format to 80-characters per line, I typically use fmt with the width option. The following example will force all lines to 80 characters, and will gracefully wrap lines if they exceed this limit: If you have any other methods for formatting text, I would love to hear them.
$ read more →Bash short cuts / hotkeys
I use bash as my primary shell, and have come to rely on the following bash short cuts:
$ read more →Viewing previous dates with GNU date
GNU date has some nifty options, and is a time keepers toolbox rolled up into an ELF executable. One really cool option in GNU date is the ability to print a date in the past using the the "--date" option, and the "days ago" format string: Now if only more vendors would include GNU date with their operating system. :)
$ read more →Searching the bash history
Bash is a great shell, and has numerous capabiltiies to make peoples life easier. One super nifty feature is the ability to search through the shell's history by hitting cntrl-r (control then the letter 'r'): Once you locate the command you want to run, you simply hit enter to execute it. Good stuff!
$ read more →Printing items before PS1
While perusing the bash documentation, I came across the PROMPT_COMMAND variable. If PROMPT_COMMAND is set, bash will execute the command assigned to the variable prior to displaying PS1: As you can see from this example, this is super useful. ;)
$ read more →