Mar 5
Handy Terminal commands for Mac OSX Leopard #1
AddHowdy! Mac OSX Terminal. A dark scary place full of text. That’s how it feels at first anyway. This is a selection of Terminal Commands that I have found particularly useful. If you are just making your first forays into OS X Terminal land hopefully they will help you out. I’m sure I have left plenty of others out, so feel free to chip in!
SSH:
To Login to a server using SSH:
ssh user@domain.com
(eg) ssh waavooc@waavoo.com (use -p for specifying port)
To Exit from the server
exitof course!
General file browsing creation and permissions in Terminal
To move to a child directory
cd directory_name
To move up a directory
cd ..
Takes you to your home folder:
cd $home
To show file structure for current location:
ls -la
To delete a file:
rm name_of_file
To create an Alias
ln -s ~/the/original/path ~/the/new/path
(eg) ln -s ~/yourapp/public ~/public_html
To view all hidden files in OS X finder
#!/bin/bash
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
Replace end of second line with FALSE to turn off viewing of all hidden files.
To change the permissions of a file or folder
chmod 755 your.file
The three digit number denotes the privileges you are applying. Generally 755 is quite a good choice if you are in doubt and need more access than you currently have. It will set all rights to the owner (You!) and read and execute rights for everything else. Use 777 with caution, this grants everyone access to all permissions!
To edit a document from the terminal
To edit a document using Textmate:
mate name_of.file
To edit document using Pico. (If you don’t have Textmate , go get it!):
pico name_of_file.php
Terminal Commands for Ruby on Rails
Do these commands from the root folder of your app:
To launch a Rails app.
script/server
To create a controller for your Rails app.
script/generate controller my_controller_name
To create a model for your Rails app.
script/generate model my_model_name
To launch the Rails debugger:
script/server --debugger
To Rake (like Make) a database
rake db:migrate
Note! You can find lots of useful information about the rake command here: http://www.railsenvy.com/2007/6/11/ruby-on-rails-rake-tutorial
To find out where your Ruby is installed:
which ruby
To create a new Rails app:
rails my_app
To create a new Rails app and specify MySQL as the database:
rails -d mysql my_app
To find out which version you are using:
ruby --version
You can do the same thing for Rails and Ruby Gems:
rails --version
gem --version
If you want to shorten things you could do this instead:
ruby -v
rails -v
gem -v
To see a list of the Ruby Gems you currently have installed:
gem list | egrep -v "^( |$)"
To quit a running Ruby on Rails app:
ctrl-c
To install a Ruby Gem
sudo gem install name_of_gem
To uninstall a Ruby Gem
sudo gem uninstall name_of_gem
To update the version of Ruby installed:
sudo gem update rails
To update the installed Gems:
sudo gem update
To update the installed version of Rails:
sudo gem install rails
MySQL commands:
You can get MySQL and lots more besides here: MySQL
May I prod you in the direction of another Waavoo! article that you may be interested in if you are thinking about installing MySQL. There are instuctions for installation of pretty much everything. phpMyAdmin is especially useful 7 step guide for installing Ruby on Rails, MySQL, Apache with PHP, and phpMyAdmin on OSX Leopard
Log in to the MySQL monitor as the root user
mysql -u root
Create a MySQL database once logged in to the MySQL monitor:
create database database_name;
Quit the MySQL monitor
\q
An example of creating a table in the MySQL monitor:
CREATE TABLE posts (
-> id INT (11) NOT NULL AUTO_INCREMENT,
-> title VARCHAR(255) NOT NULL,
-> body VARCHAR(255) NOT NULL,
-> post_date DATETIME NOT NULL,
-> PRIMARY KEY (id)
-> );
That’s it for now, I’ll add more in a future post. I hope you find some of this useful!
Posted by: Ian Alexander Wood
I was a little unsure about moving away from the nice comfy GUIs I was using to administer my setup, but since i had the terminal up for other things, I was interested in seeing if i could comfortably use it in case I didn’t have access to my other apps (or if I was on another machine). Your tips and notes have certainly helped to demystifying the process for the Terminally-Challenged. As one of the afflicted, I thank you.
Hey… To go to your home folder, just type “cd ~” or even better “cd”
[...] Handy Terminal commands for Mac OSX Leopard #1 [...]