Quantcast
Channel: Pluralsight blog » Command Line
Viewing all articles
Browse latest Browse all 14

Basic Commands for the Mac Terminal

$
0
0

The Terminal is a command line interface for the Mac that will allow you to type in commands hosting up hidden features or preferences. It can be compared to the command prompt in Windows. Be warned, however that the level of control and customization is so great you can do damage to your system if you do not know what you are doing. Disabling certain tools or settings may not always be a great idea. Despite this, the Terminal is an invaluable tool and really opens up the Mac to you so you can personalize the experience fully.

Mac OS X’s UNIX Foundation

According to Apple’s Terminal description, the Terminal offers Mac users access to UNIX through its command-line infrastructure. OS X, the Mac operating system being employed in current Macs, is based on a UNIX foundation. Apple dropped the Mac in front of OS X 10.7 Lion, but it is still widely referred to as Mac OS X. The OS comes with a graphical user interface (GUI) layer over UNIX. Here is how Apple describes the relationship and the way the Terminal bridges the gap between the Mac user interface and traditional UNIX commands:

OS X is built on an industry-standard UNIX foundation. The Terminal application allows you to access the complete UNIX environment using standard commands, tools, and scripting languages. Terminal includes numerous shortcuts that will save you time. For example, you can copy and paste text commands, and if you drag files or folders into Terminal, the correct file path appears on the command line. You can customize Terminal with your favorite fonts and background colors, including transparent, as well as manage multiple sessions from a single window using tabs.

According to UNIX.org,Unix was an operating system founded in 1969 by AT&T’s Bell Laboratories.. In 2007, Apple’s Mac OS X was certified to UNIX 03 with the release of Mac OS X 10.5 Leopard. This means that OS X is officially certified as a UNIX-based system and all the Mac machines running OS X are certified UNIX systems. However, to truly access the UNIX foundation and environment, with all that it can offer, you will need to do it through the Terminal on OS X. There are other operating systems that are often called UNIX-like, but may not share certification or be considered in the same OS family at all.

This is why Macs are not just systems aimed at graphic professionals or creative types. The UNIX foundation makes them useful for other purposes as well that IT types can benefit from. To put it plainly, when you open the Terminal, you are accessing UNIX. On the other hand, when you use the standard Mac interface and desktop in recent Macs, it’s OS X. However, keep in mind to get the UNIX compiler you will need to register with Apple as a developer and install XCode on your Mac. Alternatively, you will need to install XCode tools from extra/optional tools on your Mac installer disc. XCode is a C development environment. It will allow you to develop in C or C++. You will be able to compile programs and do many other things beyond just simple command line options changing fonts and the like. With that said, let’s look at some basic commands the Terminal has to offer.

Navigating the Terminal

In order to open the Terminal, go to your Applications folder on your Mac. Then, go to Utilities. If you are a Mac OS X 10.6 Snow Leopard user or if you use OS X 10.7 Lion, you can go to Launchpad and find it under utilities as its directory is /Applications/Utilities/Terminal.app. The terminal icon looks like this and you can actually place it on your Mac’s Dock:

Terminal App Icon

Once you launch Terminal, you will be shown a command line interface that looks something like this:

Mac Terminal Command Line Interface

Now you will be able to type commands from the Terminal and have access to many new options. For instance, if you are a Lion user and want to empty out your Launchpad with a single command, rather than having to delete the apps one-by-one, enter this command line into the Terminal:

sqlite3 ~/Library/Application\ Support/Dock/*.db “DELETE from apps; \
DELETE from groups WHERE title”; DELETE from items WHERE rowid>2;” \
&& killall Dock

If you performed this command correctly, your Launchpad should be empty and you should be able to add the apps you want in it yourself. You do this by dragging them from your desktop to the Launchpad icon on your dock (if it is located there). To reset the Launchpad back to defaults, enter this command line:

rm ~/Library/Application\ Support/Dock/*.db

Another useful Terminal command if you are a Lion user, is to allow your graphical interface to show you the Library folder. Apple has hidden it in the home directory by default in Lion. A lot of your user data in apps, especially games, is stored in this folder, yet it is hidden from view by default. To make it visible, enter this command line in the Terminal:

chflags nohidden ~/Library

Now, let’s take a look at some commands that are not just aimed at Lion users, but OS X users as a whole. If you want to hide specific folders, like how the Library folder is hidden for Lion users, you can enter this command line in the Terminal:

chflags hidden /path/to/folder/

This is a general path. To be more specific, if you have a folder named “Games” in your Desktop directory, you would enter this command in the Terminal:

chflags hidden ~/Desktop/Games/

The folder will even become hidden from the finder once you enter this command line. This will even include other files associated with the folder or located inside it. You can hide it further by excluding the folder from Spotlight indexing. To do this, go to Spotlight from system preferences in the Apple menu. Then, click on the Privacy tab and drag & drop the folder you want to exclude form indexing – as anything in that list is hidden. This is how this process should look like (you can read more about this at OSX Daily):

Exclude Folders from Spotlight Indexing

However, keep in mind that anyone who knows how to operate the Terminal will still be able to find the folders you’ve hidden. To access the hidden folders, you will need to go to Finder. Then in Finder, enter these keystrokes: Command+Shift+G. This will bring up a “Go to the folder” window. Now, enter the same path as you did when you hid it:

Access Hidden Folders in the Finder

If you want to see a list of all the hidden folders on your system from the Terminal, enter this simple command line:

Ls /

This means either an uppercase “L” or a lowercase “l” (don’t be confused by some guides with the l almost looking like a 1). Also make sure to have a space between the s and the / symbol.

Conclusion

The options are endless when it comes to the Terminal and it will truly allow you to open up your Mac. It will not feel like propriety OS anymore. Apple is often regarded as a company that has a closed ecosystem. However, for users who truly know learn how to navigate around the Mac environment with UNIX and the Terminal, this perception will change. There are many other commands to consider and look up if you want to truly learn how to use the Terminal. This was just a small taste what it can offer.


Viewing all articles
Browse latest Browse all 14

Trending Articles