Command Line Tips
Command Line Tips
Some of the software listed on my site is available as source only. This requires you to build your application. This can be a sobering prospect to someone who has never done this before. There are many people that have gone to the trouble to provide step by step instructions to help those of us with no experience with building OS X applications, but they often assume we have some basic knowledge. This may be an assumption that your terminal is running the same shell that their’s is. Your thought may be “what’s a shell”? I will cover basic things from the most basic. Please feel free to email me if I am unclear, or if you have better suggestions.
Terminal
The Terminal application is found in the Utilities folder in the Applications folder for nearly all versions of OS X. Apple’s Terminal application is not designed to communicate through a serial port, but directly to UNIX. Launching Terminal will give you a window where you can interact with you computer using the command line rather than the graphic user interface, Aqua, that you may be more used to. Terminal’s behavior is not necessarily identical from system to system, it can be customized. The default shell is set in System Preferences, see this link. The Terminal in Lion supports multiple windows, multiple tabs, and full screen mode. There are many third party terminal programs. If you have a desire for the nostalgic, look into Cathode.
Here is a tutorial on the basics.
Useful App to link Finder windows to Terminal
ZIPZAPMAC has Go2Shell. It is a button at the top of any Finder window that launches Terminal and puts you in that same directory of the window you launched it from.
https://zipzapmac.com/go2shell
Shells
A shell defines the interface to the operating system in Terminal. Keywords for looping, accessing parameters of previous commands, and the search path for executables. Bash has been the default shell since Panther, but don’t count on your default shell being bash no mater what version of OS X you are using. Depending on how you have upgraded your OS X through the years, you might find, as I did, that you are using the tcsh shell. tcsh is a fairly popular shell, a derivative of csh (the old C shell), but not nearly as popular as the bash shell for OS X users. If you are not using bash, I recommend at least trying it, especially if you have trouble building applications.
Before we go into shells, a few explanations:
The ~ character in UNIX is the same as typing /Users/YourAccountName
File names that start with . are invisible files, many people suggest you use a command line editor to alter these, but there is a OS X Aqua free text editor that will ‘see’ invisible files and also write the file with the UNIX line endings.
It is Text Wrangler. You will need to click the “Show Hidden Items” check box in the File Open window. You can also make these file visible, see here.
Bash
When you login with bash as your default shell, two (at least) files are run to initialize your environment (such at paths for executables). The first one I know of is global for all users:
/etc/profile
The second one is specific to your account and may have one of three names (but only one will be run):
~/.bash_profile
~/.bash_login
~/.profile
Here is a list of the bash commands.
Tcsh
When you login with tcsh as your default shell, there are two script files that get run.
.login
The second one will be one of these (but only one will be run):
.tcshrc
.cshrc
Here is a link to some articles when tcsh was the default shell for OS X.
These script files are where you need to look for you path setup.
Paths
You will often be following a recipe from a web site to build a tool you need and run into:
Command not found.
Before going to the trouble to edit your login scripts, you can add a directory to your executable search path from the command line. You use the same syntax as in your specific login/profile script (shells don’t share the same script language)
bash
PATH=$PATH:<your new directory>
export PATH
Remember to export your path after updating it if you want to use your new path in other shells, or when you return to Terminal later. If you are just experimenting with a path, and want to easily ‘undo’ any path experiment, first start a new shell (just type bash) modify your path but don’t export, and do your experiment. When you are done simply exit that shell and all will be as before.
tcsh
set path = ( "<your new directory>" $path )
Xcode & Xcode command line tools
These days you can get Xcode from the App Store, if you are using the latest version of OS X. Otherwise you need to get it from your old install CD, of from https://developer.apple.com/ and search for it. You will also need the command line tools. These are not installed automatically. You can find them at this link below (you will need a developer account)
https://developer.apple.com/downloads/index.action#
Hard disk format (Case-sensitive)
Although unlikely, if you re-formatted your drive before installing OS X, and decided to experiment with the setting
Mac OS Extended (Case-sensitive)
then you made your life a whole lot more difficult. Even though classic UNIX is case sensitive, so many people have drifted away from strict case rules that you may have made it impossible to build many tools.
Additional Reading
Learning The Shell is Linux centric, but most of the information applies.
Learning the UNIX Operating System is a good book.
This site has a bunch of command line tips.
Visit my other pages: