If you’re working in Terminal on your Mac, you need to know the most important UNIX commands: those that work with directories, those that work with files, and miscellaneous but commonly used commands.
- Mac Os X Terminal App
- Os X Terminal For Windows 10
- Os X Terminal For Windows 6
- Mac Os X Terminal Emulator For Windows
Mac OS X Tips points out that in Mavericks there's an easy way to launch Terminal directly from a folder of your choosing now. Mac: By default, Terminal always launches into your home directory. In this post, I will about Windows Command Line (CMD) and Mac OS Terminal Navigation Commands. Knowledge of CMD/Terminal commands may be needed for using command line interfaces (CLI) of applications where Graphical User Interface is missing, or when CLI provides a faster/easier way to perform a task. Let’s see some of the commands.
Folders are called directories in UNIX. Commands that refer to filenames, as most do, assume that you’re talking about files in the working directory. When you open the Terminal window, the working directory is set to your home directory, abbreviated ~. Bash shows you the current working directory and your username to the left of its prompt. The following table lists common directory-related commands.
Command | What It Does |
---|---|
ls | Lists the names of the files in the working directory. For more complete information, use ls –alF (. |
cd directoryname | Changes the working directory to the one you named. |
cd .. | Brings you up one directory level. |
cd | Returns you to your home directory. |
pwd | Displays the pathname of the current directory. |
mkdir newdirectoryname | Makes a new directory. |
rmdir directoryname | Removes (deletes) an empty directory. |
As in Windows, you can redirect the output of a command to a text file. So if you want a record of the files in a folder, type cd, followed by a space, drag the folder’s icon to the Terminal window, and press Return. Type ls > mydirectorylist.txt and press Return again. A file named mydirectorylist.txt will appear in the folder you chose. You can open the file in TextEdit to see a list of the files in that directory.
This table lists commands commonly used when working with files in the Terminal window.
Command | What It Does |
---|---|
cp filename1 filename2 | Copies a file. |
chmod | Changes permissions for access to a file. Study the man page before using this one. |
diff | Compares two files line by line (assumes text). |
more filename | Displays a text file one page at a time. Press the spacebar to see the next page; press Q to quit. The man command works through more. |
mv filename1 filename2 | Moves a file or changes its name. |
rm filename | Removes (deletes) a file. |
This last table explains other handy commands that anyone getting started in Terminal will likely want to know.
Command | What It Does |
---|---|
Control+C | Terminates most operations. |
date | Displays the current date and time. |
echo | Repeats whatever appears after the command (after expansion). |
help | Displays a partial list of bash commands. |
history | Displays the last commands you typed. You can redo a command by typing an exclamation point (!) followed immediately (no space) by the number of that command in the history list. To repeat the last command, type !!. To repeat the last filename, type !*. |
pico | A simple UNIX text editor. |
ps | Displays a list of running processes. |
sudo | Lets you carry out commands for which the account you are using lacks authority. You will be asked for an administrator’s password. |
When you’re working in Terminal, you don’t have a Trash Can to which deleted files are moved pending ultimate disposal. Delete it, and it’s gone. In general, UNIX has no Undo function.
Get Software
Terminal Scripts for OS X are a set of “scripts” that invoke the Terminal and ssh programs distributed with OS X.
- Terminal Scripts for OS X – 107KB (zipped file)
MD5 (Autumn08-Terminal-scripts.zip) = 1cd76d1104998c2a2a79a7e172083a09
About These Scripts
NOTE: Starting with OS X 10.3 (Panther), the Terminal program supports a variety of terminal emulations. Unfortunately, the default (xterm color) is not likely to work on many systems, including most of the UW central systems. You MUST change this default. Run Terminal (e.g., from Applications->Utilities) and use Terminal->Preferences to bring up the preferences panel. From the pop-up list next to “Declare terminal type as:” select “vt102” (or vt100).
To connect with ssh, open the OS X “Terminal” app and type in the command “ssh YourUWNetID@UWHost”. For example, if YOUR UW NetID were “myuwnetID” and you wanted to connect to homer, you’d enter “ssh [email protected]”. If you have used your UW NetID as your OS X login ID then the ID can be omitted. Using “ssh -2” uses v2 of ssh instead of v1, for those hosts that permit (or require) it.
Printing directly from Pine may work if you are using Terminal version 1.5.1 (OS X 10.4.11) or BEFORE, but appears to be broken in the current version (as of this writing, 2.0.1 with OS X 10.5.4), but will only go to the current default printer.
Applescripts for Terminal
Starting with OS X 10.2 (aka Jaguar), this can be made a little easier with some fairly simple AppleScripts (thanks to David Linker and Scott King for inspiration – and more 🙂 ). Find some examples here in the same folder with this document, in both “runable” and “editable” (-Template) forms. Double-clicking the “Template” versions should run the AppleScript Editor to let you modify the script. Double-click the “regular” copy (without the “-Template” name) to run the script.
Terminal to UW Hosts
This is the most general (and complicated), it prompts for UW NetID and then for a selection from a list of known hosts. You can change the list of hosts by editing the script. Probably best in a “lab” where many people connect to many different hosts. The example list is {Dante, Homer, Other(prompt me)}.
Terminal to Vergil (or Homer or Shell)
It is easy to make “clickable” icons that open a connection to a given host, after prompting for the UW NetID.
Mac Os X Terminal App
Terminal to MyUWHost
Lastly, you can include everything in the script, so when you double-click it it just connects (and asks for a password, of course). This example, MUST be edited. To use it use the Script Editor to put in your NetID and desired host before use.
Keynes Terminal Window
This one is a little different, it is a file of saved settings for the Terminal application.
The behavior of saved “term” files is somewhat different in OS X 10.5 from previous versions.
Keynes With OS X 10.5.2 (and presumably above)
The Terminal program allows you to keep a “library” of settings, then open sessions using any of those. To add the Keynes settings to your library:
- StepsActions
- Copy the “Keynes Window.terminal” (be sure to use the “.terminal” file, not “.term”) file to your Documents folder from the “Terminal Scripts” folder.
- Run Applications -> Utilities -> Terminal.
- Select Terminal -> Preferences.
- At the bottom of the list of settings profiles find the “gear” button and select it to expose a list of options, select “import” from the list.
- If necessary, navigate to your Documents folder (it may already be pointing there), locate and open the “Keynes Window.terminal” file you copied there in step 1. A new “Keynes Window” profile is added to your list. You may make it your default profile if you use Terminal mostly (or only) for connections to Keynes, but it is usually not recommended.
- Close prefs, quit Terminal.
- Run Terminal again (you may want Terminal in your Dock…), if the Keynes settings are your default, a login window to Keynes appears.
- Otherwise (recommended) use Shell -> New Window -> Keynes Window.
Now that you have a separate profile for Keynes connections you can easily edit the preferences in that profile, choose font type and size, colors, etc. as you prefer. If the “Enter” key is not working to “send a screen”, use “control J” instead. If using a laptop, remember that you may have to use the “fn” key to stroke “Enter” (as fn+return).
Keynes With OS 10.3 – 10.4
When you double-click the “Keynes.term” file a Terminal window will open, and open a connection to keynes.u.washington.edu, that window will have the settings that SOME users are reporting allows them to connect to the Keynes (Administrative) system. The “Enter” (far right of the keypad) key should now work to “send screens” in Keynes apps.
Using Mac OS X Terminal With Keynes
The keypad digits will likely NOT work, use the top-row digit keys instead. Note that having the setting in Terminal for “strict vt100 keypad behavior” on is the essential setting for this. Note that if using the keypad for numeric entry is STRICTLY required, you may be able to get that working by turning the “strict” behavior off and entering the “Enter” keystroke with “control J”. Printing that works via “ansi print escape” (much of the student data base system) will NOT work correctly though the screens CAN be captured (and then printed) using the “Grab” utility.
NEW with OS X 10.3 are some problems with lots of “inverse video” being drawn on the Keynes screens, just pressing “Enter” without entering any data, may clear the screen some. There are reports that the old MacSSH program (run under “Classic”) in OS X DOES work with newer versions of OS X (10.2.6 – 10.4.x). This may be a better solution for Keynes users, however since “Classic” is not supported on Macs using “Intel” hardware or with system 10.5 and above, it isn’t going to work in those cases. Printing, after setting up a default printer WITHIN Classic, should also work using MacSSH.
Other Uses for “.term” Files
NOTE: This no longer seems to work as described below in OS X 10.5. It may still be of interest to those running older systems. You can create multiple profiles within Terminal and associate a startup command with each profile (settings -> shell).
All the settings in the Terminal Window Settings are preserved in a “.term” file created with the File->Save as command, you can adjust font choice and size, colors, transparency, etc. You can also (perhaps too easily…) make these choices effect the DEFAULT setup for Terminal, so use this with some caution.
You can also directly edit the .term file, for example by using TextEdit, and this gives you access to some things that the Windows Settings dialogs won’t, specifically you can edit the “Execution String”. Find the lines
“<key>ExecutionString</key>”
“<string></string>”
On the second line, insert whatever command you want executed every time you open this .term file between the “<string>” and “</string>” statements. For example, to make a connection to homer automatically you could put
Os X Terminal For Windows 10
<string>ssh -2 [email protected]</string>
Os X Terminal For Windows 6
in THAT place, instead of using the script above, this would also then let you control font, color, etc. and still have a “double-clickable” file/icon for the homer terminal.
Mac Os X Terminal Emulator For Windows
See a problem on this page? Let us know.