Getting Over Terminal-phobia

By on July 31st, 2012

Terminal is probably the scariest interface I have ever used. Its intense display looks heavy duty, only usable by super-geniuses and hard core programmers like Mark Zuckerberg. It also reminds me of the computer system from the old movie War Games.

War Games

In the movie the two kids almost cause this:

War Games

a scenario where the US thinks Russia is getting into position to start a nuclear war because the kids are playing around on this terminal like computer, hence my obvious and completely reasonable association of terminal with World War III.

However, when used correctly terminal can make life a lot easier. Thanks to Zack, who’s in charge of System Admin & Operations  here at Barrel, I have learned some pretty nifty short cuts and commands, so rather than feeling like I am about to blow-up the world, I just get to feel insanely smart.

First things first. Change the color (my preference is ocean, which I find helps soothe the WWIII atmosphere, but grass isn’t so bad either).

Next, actually entering info into terminal. The language of terminal sounds like absolute gibberish at first. Chmod, chown, mkdir, rm, sudo–they also sound like complete nonsense, until you realize everything is just an abbreviation and an elimination of as many vowels as possible (mkdir= make directory, chown=change owner, cd= change directory, etc.). This realization was the first step in discovering terminal isn’t so bad afterall.

The first thing I learned was how to chmod things (a.k.a change the permissions of files). The perfect starter command because its really hard to crash a system when using chmod. Chmod is especially helpful when you want to change the permission in all files in a folder.

First you navigate through the folders til you find the one you want to chmod. For me all my files start out in a folder called Sites so I simply enter in ~/Sites/the_name_of_the_grandparent_folder/the_name_of_the_parent_folder. A quick and easy shortcut is hitting tab, which completes the file name for you (e.g. if I typed in the_name and hit tab it would auto complete to the_name_of_the_parent_folder). If you hit tab and nothing happens, hit it twice and the possibilities of the auto complete will be displayed. Once you have found the folder you are looking for you type in the command chmod -R 755 the_name_of_the folder. The -R means it will recursively apply the permissions (e.g 755) to everything in the folder.

Another useful thing Zack taught me was how to set up a new website on our server. The most important commands from this are:

  • mkdir directory name (which makes a directory)
  • cd (which moves you in and out of the directory, / to go in further and .. to go out of the current folder)
  • tar -czvf filenameOfNewFile.tar.gz filename_you_want_to_tar (to make a zip file)
  • tar -xzvf filename.tar.gz –strip 1(which unzips it and removes the previous initial path)
  • find -name ._\* |xargs sudo rm -v  (which gets rid of the ._ in front of file names when the file unzips weirdly)**Here I would just like to point out comes another useful trick piping. The | takes everything found in the search (which in this case was all of the files with ._  in front) and “pipes” it into the command sudo rm -v (super user do remove)
  • mysql commands on making a database:(for this example the database name is sandwich_db with user peanut_butter and password jelly, and the hostname is yummy)
  1. mysql > create database sandwich_db; (which creates the database)
  2. mysql > create user ‘peanut_butter’@'yummy’ identified by ‘jelly’; (which creates a user);
  3. mysql > grant all on sandwich_db.* to ‘peanut_butter’@'yummy’ identified by ‘jelly’; (which grants the user access to the database you have just created)**DON’T forget the apostrophe around the username and password and hostname and the semi colons at the end of the commands!
  • If you want to transfer a database and put it in the new database
  1. dump the database into a sql file
  2. find and replace the old siteurl with the new one
  3. enter the command: mysql -u peanut_butter -p sandwich_db < sql_db_file_you_just_made.sql

These little nuggets helped to turn terminal from this

scary comp

to this

friendly comp

Share
back to top

2Comments

  1. Katie Chin says:

    Haha I love the images!

  2. Patrick Kunka says:

    This is great Taylor. I’m in the process of overcoming my terminal fear too so it’s all very familiar!

Leave a comment

Cancel Reply