Using Terminal By Josh Blagden | JB - Mac Help | JBlagden

Using Terminal By Josh Blagden

Despite being rather intimidating due to its lack of a GUI(Graphical User Interface) and requirement of specific commands, Terminal is a very useful program which you'll find in the Utilities subfolder of your Mac's Applications folder or Launchpad. Those familiar with Windows will recognize it as similar to Command Prompt. If you are unfamiliar with it, I'm not surprised. I didn't use Terminal until my first programming class, where I used it to run my Java programs, which I'll discuss later. 


Terminal can be used for: 


1. Running Command-Line Programs 

2. Converting DMG files to IMG files

3. Cloning hard drives

___________________________________

Running Java command-line programs

I mainly use Terminal to run Java programs that I've written. I can use Terminal to run them because they're command-line programs, not programs with Graphical User Interfaces which most people are used to.


There are three main steps to running a Java program in Terminal:

  1. Directing Terminal to the directory of your program’s containing folder. To do this, type “cd” and the file-path which leads to your file. Press Enter. 
  2. Compiling the .java file into a .class file, which means the java file is compiled into Java bytecode, which will be converted into binary code by the Java interpreter. To do this, type “javac” and the name of your java file with the .java extension. Press Enter.  
  3. Run the program. To do this, type “java” and the name of your file, without the .java extension. Press Enter. Next, your program will run.


My program is called golfScores because I created it to add up golf scores. The file path will be different for everyone, but it will always be preceded by “/Users”. Also, “cd” means “change directory. For some unknown reason, this is required to be able to run a Java program on a Mac, even though it’s not needed to run a Java program on Windows. Here’s what Terminal will look like so far:

This is what step 1 should look like: 

Screen Shot 2014-09-01 at 7.54.38 PM

This is what step 2 should look like: 

Screen Shot 2014-09-01 at 7.54.53 PM

This is how step 3 should look: 

Screen Shot 2014-09-01 at 7.55.16 PM

Now my program is running. 

For those of you who are new to either programming or Java programming specifically, I made the variable which holds the date a string so the program won’t get hung up by slashes or dashes in the date; all other data type such as int or double are only for numbers, not letters or even characters such as slashes.

—————————————————————

Converting DMGs Disk images to IMG Disk Images

Terminal is also useful for converting DMG disk image files to IMG image files. However, the only reason to do that is if you’re running OS 9 through Sheepshaver or are running it on an old Mac. To do this, direct Terminal to the enclosing folder of your DMG.

There are three steps for accomplishing this goal:

1. Direct Terminal to the folder which houses your DMG(refer to step 1 of the upper section) and press Enter.

2. Type(without quotes): “hdiutil convert” , the name of the file with the .dmg extension followed by “-format Rdxx -o” and the name of the desired IMG file and press Enter.

Step 1 will look like this(file path will vary): 

Screen Shot 2014-09-06 at 5.24.21 PM

Step 2 will look like this: 

Screen Shot 2014-09-06 at 5.26.29 PM

Completion of this process will look this: 

Screen Shot 2014-09-06 at 5.28.59 PM

Now you can use your OS 9 program in OS 9 on an older Mac or in Sheepshaver.


—————————————————————

Cloning Hard Drives

The last thing I’ll cover in this article is using Terminal to clone hard drives. I’ve only used this to clone the hard drive of a first generation Apple TV. I won’t show any screenshots because this is a long process. Keep in mind that this won’t work if you’re trying to make a clone of a drive which is larger than the destination drive.

1. Plug in the old hard drive into your Mac.

2. In Terminal, type “diskutil list” and press Enter.

3. Find out the identifiers of the old  hard drive and the new hard drive which you would like to use.

4. Type “dd if=/dev/disk# of=Users/SharedAppleTVImage.dmg bs=1m”. By the way “/de/disk#” will be the disk number of the old hard drive. This will create a disk image of the old hard drive, provided that your Mac has sufficient hard drive space. In the case of a first generation Apple TV, the disk image will take up 40 gigabytes. In the case of an older MacBook, the disk image could take up 500 gigabytes, in which case, you might not have enough space on your Mac’s hard drive. 


© Joshua Blagden & Justin Barczak 2013-2015
www.000webhost.com