UNIX command sytnax hinters

The UNIX commands “find” and the combo of “tar” and “gzip” are powerful commands I use quite often. What actually happens, especially in the case of tar/gzip, is that I use them almost daily in shell scripts I have written for one purpose or the other. When I try to use “find” or create or extract .tar.gz archives on the command line, I sometimes end up taking a couple tries at it, wrestling with the proper syntax.

Problem:
I don’t use these particular tools on the command line often enough to remember the syntax. Man pages have a wealth of information, more than I generally need for my particular purpose.

Solution:
Syntax hinters available on the command line.
Example:
[unknown@dog ~]$ syntax4tar
  create: tar -cf - *.sql *.ksh | gzip > file.tar.gz
  extract: gzip -cd file.tar.gz | tar xvvf -
[unknown@dog ~]$ syntax4find
  find ./ -name *.sql -print
[unknown@dog ~]$

I currently use aliases in my .profile. If I expanded this concept to several hints, I would maybe change it a script called syntax4 and call it like syntax4 find, syntax4 tar, etc.

Here is the code I put in my .profile (for the Korn shell):
# syntax hinters
alias syntax4find='echo " find ./ -name "*.sql" -print"'
alias syntax4tar='echo " create: tar -cf - *.sql *.ksh | gzip >file.tar.gzn extract: >gzip -cd file.tar.gz | tar xvvf -"'

I have been mostly successful in dropping these aliases straight into my .bashrc file at home. My one glitch is that the linebreak character does not seem to be recognized in bash, so the string comes out as one really awkward long line instead of two. Will update if I find a resolution.

Update: 2005/10/22
I posted my problem over at the [gnu.bash] Newsgroup, and a James Franklin came up with a Bash-based solution. I suspect that this code is portable back to a Korn shell, but I will have to check for sure. It is definitely Bash friendly:
alias syntax4tar="echo -e ' create: tar -cf - *.sql *.ksh | gzip > file.tar.gzn extract: gzip -cd file.tar.gz | tar xvvf -'"

Update: 2005/10/23
More tar tidbits:
A rose is a rose is a a rose, but all tars are not created equal. Specifically some UNIX tars allow the specification of a single of double F flag, which excludes version control directories (RCS, SCCS), compile object files (*.o), etc. GNU tar, which comes with the Linux gnu/Linux system I use, has a very different use for the F flag:
-F, --info-script F --new-volume-script F
run script at end of each tape (implies -M)

What to do? Give up the F flag for the X flag. X is for eXclude, but it assumes nothing, so you have to be explicit in what you want excluded. This flag can be used in conjunction with the I flag (Include) to be very specific about the files rolling into the tarball.

This entry was posted in computers/programming. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *