Mostly Linux & Python syntax notes and hyperlinks.

Wednesday, August 19, 2009

selective extraction from tar files using pax

I put all the changes I had to make into a single tar file. The tar program removed the leading '/'s from two of the files. I wanted to extract them without creating an entire directory structure. I found this:

http://www.unix.com/unix-dummies-questions-answers/15182-extract-tar-files-without-creating-directory.html

which led me to pax.

I found I could do what I wanted here with three options:

pax -r -i -f [archive] [pattern_matching_desired_file]

The -r is for read from an archive.
The -f is to give it the name of the archive file.
The -i is for name the pulled out file interactively. This meant I had to rename the file, which allowed me to leave out the parent directories.

(There are many more options on the man page, of course!)


Here's how to pull a file out of a tar without having to create all the subdirectories:
$ls
mychanges.tar
$ tar -tvf mychanges.tar
-rw-rw-r-- sam/zac 193 2009-05-18 06:02:23 dir1/changed1.c
-rw-r--r-- sam/zac 3708 2009-05-18 05:57:05 dir2/changed2.py
-rwxr-x--x sam/zac 9708 2009-05-18 05:51:34 dir3/dir4/dir5/dir6/changed3.ksh
-rw-rw-r-- sam/zac 2282 2009-05-18 05:54:57 dir3/dir4/dir5/dir6/dir7/dir8/dir9/cpx.cfg
To pull out the changed3.ksh without creating its parent directories:
$ pax -r -i -f mychanges.tar *.ksh

ATTENTION: pax interactive file rename operation.
-rwxr-x--x May 18 05:51 dir3/dir4/dir5/dir6/changed3.ksh
Input new name, or a "." to keep the old name, or a "return" to skip this file.
Input > changed3here.ksh
Processing continues, name changed to: changed3here.ksh
Now you have your file in the current directory.
$ ls
changed3here.ksh mychanges.tar

To pull out another:
$pax -r -i -f mychanges.tar *cpx.cfg

ATTENTION: pax interactive file rename operation.
-rw-rw-r-- May 18 05:54 dir3/dir4/dir5/dir6/dir7/dir8/dir9/cpx.cfg
Input new name, or a "." to keep the old name, or a "return" to skip this file.
Input > cpx.cfg
Processing continues, name changed to: cpx.cfg
And there it is:
$ ls
cpx.cfg changed3here.ksh mychanges.tar

My Linux/Unix bookmarks: cut, join, sort

cut assumes tab delimiters. To cut using space as a delimiter, use -d' '
$ cat > foo
a b c d
e f g h
h i j k
a b c d
$ cut -d' ' -f 1,3 foo
a c
e g
h j
a c
join join two files by a common field. (after you sort.)
join [options] file1 file2

sort

Tuesday, August 18, 2009

Installing Firefox 2.0 for Mac OSX.3.9 (so you can run Google docs)

If you have a creaky old mac that can't handle an O.S. greater than 10.3.9, then this is how to find the latest Firefox that runs on it:

You can follow this link

to the FTP site

ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/2.0.0.20/mac/en-US

From there you can download the .dmg file.  Double click on it to install the latest Firefox that will run on X.3.9.

Then you can run Google docs on your old iMac.  Google Docs needs Firefox 2 or Safari 3 to run on X.3.9.

Caution!!
Don't try to copy the .dmg file from one user to another on the same iMac.  Just download it again to the other user's desktop.

{....OK, Guille's addenda to Margie's comment. I don't know if dropping down dmg files all over the place creates havoc (although I wouldn't be surprised if it did).  This is what happened when Margie opened a dmg and then rebooted....}

I tried to open a copied .dmg, and ended up in some sort of  infinite loop when I tried to double click on the .dmg as the other user.  When I rebooted (about all I could do, or so I thought, since I couldn't kill the program) I ended up with the waiting for local disks forever screen.  I suppose it's because the .dmg is seen as a disk, and it wouldn't open.

Guillermo fixed this by unplugging our external hard drive, rebooting, then plugging it back in.

{...OK,  Guille's addenda continued...So I'm looking at this mac endlessly trying to do something with a local disk ...what exactly, god knows 'cause SJ feels it's none of my business & heaven forfend he make it obvious to set up a verbose boot mode (I'm sure there is one but I have no idea how to get that to happen)...so where was I, oh...I guess. If the disk system is the problem then maybe changing something like unplugging the external hd might do it. So to quote Bugs Bunny..."I dood it" and voila!...she continues to boot, goes to login dialog and I login. I plug the ext hd back and after a few tics she mounts. I then update the firefox by dropping the program into applications (after proper authentication of course)  and removing all signs of available firefox dmgs, do a restart and next thing you know the old imac is back to its hippie self (it is a flower power mac after all).

Finished by cleaning up the open dmg in Margie's account, and sure enough right version of firefox is up.

So to summarize: Mac's on OS10 go fubar periodically just like any other computer (I'm a great fan of "Crash Different")...I just wish I had some idea as to why?
... /end Guille's rant}

Friday, August 14, 2009

find syntax

from http://www.athabascau.ca/html/depts/compserv/webunit/HOWTO/find.htm#EX01:

find . -name "filename" -print

This command will search in the current directory and all sub directories for a file named filename.

tar with exclude, rm files starting with -

To tar up a directory without the subversion folders embedded throughout:

$ tar cvf file.tar directorytotar --exclude .svn

or

$ cat > exclude
.svn
[control-D]

$ tar cvjf file.tar directorytotar -X exclude

If you goofed and tried it this way first:
tar cvjf -X .svn file.tar directorytotar
tar --exclude .svn cvf file.tar directorytotar

You're then stuck with a file named --exclude or -X

You can't do

$ rm -X
rm: invalid option -- X
Try `rm --help' for more information.


Instead, do rm ./-X or rm -- -X

$ rm ./-X
rm: remove regular empty file `./-X'? y
removed `./-X'

from http://www.cyberciti.biz/faq/unix-linux-remove-strange-names-files/

Jared Richardson said...

At the NE-Jug meeting last night, Jared Richardson said to start a blog in which you write everything you've had to look up. So here it is: margie's tech blog.

margietech was taken.