SSH, Unix commands & RegEx

This summer I am sitting in on a computational linguistics course. It is the first instruction I have had about UNIX. Pretty Awesome.
This has required me to do some googling looking from terminal commands.

This is kind of a sketch of where I have been.

UNIX:
http://www.osxfaq.com/Tutorials/LearningCenter/

SSH:
http://kimmo.suominen.com/docs/ssh/
http://ss64.com/osx/

TERMINAL:
http://homepage.mac.com/rgriff/files/TerminalBasics.pdf

grep:
http://www.thegeekstuff.com/2009/03/15-practical-unix-grep-command-examples/
http://en.wikipedia.org/wiki/Grep
http://www.computerhope.com/unix/ugrep.htm

Regular Expressions:
http://www.zytrax.com/tech/web/regex.htm
http://www.regular-expressions.info/tutorial.html
http://gnosis.cx/publish/programming/regular_expressions.html

RegEx and Unicode:
One of the issues that I have had with RegEx has been what is a natural class? i.e. [A-Z], [A-Za-z], [0-9], etc. As a linguist I deal a lot with IPA characters, subscripts, superscripts, unicode, and diacritics. How am I to define a natural class with these? Can I define a natural class based on the phonology of the language?

So I did some more searching:
http://unicode.org/reports/tr18/
http://unicode.org/reports/tr18/tr18-5.1.html
http://icu-project.org/docs/papers/iuc26_regexp.pdf
http://courses.ischool.berkeley.edu/i256/f06/papers/regexps_tutorial.pdf
http://wapedia.mobi/en/Regular_expression?t=5.

RegEx+PERL+Unicode:
http://perldoc.perl.org/perlretut.html

PERL:
http://www.enginsite.com/Library-Perl-Regular-Expressions-Tutorial.htm
http://www.cgi101.com/book/connect/mac.html
http://www.mactech.com/articles/mactech/Vol.18/18.09/PerlforMacOSX/index.html

Python:
http://www.amk.ca/python/howto/regex/

SSH and Terminal

I used an ssh connection from the Terminal today for the first time!

Picture of Apple Terminal

Terminal

I feel like a real man now.
I needed to transfer a 106MB folder from one subdomain to another subdomain on my DreamHost webserver. It has been my experience that whenever I copy or move folders with a lot of sub-folders that something(s) do(es) not get copied all the time or all the way. So I needed to archive my files and move them as a single object. But I do not think it is possible to zip files with an FTP client (at least not with Interarchy). For a solution I turned to ssh and a lot of googling.

So to ssh into my webhost I had to enable a user from the DreamHost panel.

Picture of  panel to Enable ssh for user on DreamHost.

Panel to Enable ssh for user on DreamHost.

User Account Type Page at DreamHost

User Account Type Page at DreamHost

Second image from another tutorial.

Then I had to open terminal and create a key. I found some sensible directions in the knowledge base.

    To generate a secure public/private key pair to log in securely, and without a password (if you want):

  • In Terminal type: ssh-keygen -d
  • Hit the “enter” key three times.

    Replacing “username” and “yourdomain” with your FTP username and your-domain,

  • copy & paste/type the following into Terminal:

    ssh username@ftp.yourdomain.com 'test -d .ssh || mkdir -m 0700 .ssh ; cat >> .ssh/authorized_keys && chmod 0600 .ssh/*' < ~/.ssh/id_dsa.pub

  • Press return/enter key again.
    Wait for it to ask for the Password:

    Enter the password of the FTP user who's username you inserted in place of the example USERNAME@ftp.yourdomain.com above.
    If it asks you for the password multiple times, type in the same correct password each time.

    Then you will be at the root in your Terminal window.

  • type: ssh username@ftp.yourdomain.com
  • You're logged in!
    Now any time you want to log using SSH you can just repeat
    ssh username@ftp.yourdomain.com
    from the command line (Terminal), no need to repeat the other steps.

So from here on I was in my webhost but still didn't know how to get around. Evidently I needed to use long paths so $ cd /home/username/directory would move me from directory to directory. I could not just $ cd /directory.

Once I was able to get to the directory I needed to archive, I still needed the archive commands.

I thought I wanted to use zip as my archive utility. The zip command to do that would be:
$ zip -r folder.zip folder
Though my friend Daniel said that I might should have used tar gunzip tar.gz instead of using the zip command: "Zip compresses each file separately and then archives. Tar+gzip or tar+bzip2 archives first and then compresses."

The commands to use the tools Daniel suggested would be like the following:

tar+gzip
$ tar -cf blah.tar folder/
$ gzip -9 blah.tar

gzip compressed tar I guess this is a combination of the above two commands. Not sure. Didn't try it.
$ tar czvf folder.tgz folder

bzip2
$ tar jcvf filename.tbz folder

After the file was compressed I used Interarchy to move the single zip file to its new location. I also needed to unzip the file. (I also read this.)
To unzip the file I navigated to the directory where the file was located and then used this command:
$ unzip folder.zip folder
I had to use the long path too. So it was really:
$ unzip /home/username/directory/folder.zip folder

What a sense of accomplishment!