- Execute commands and run tools in Terminal on Mac
- Execute commands in the shell
- Terminate commands
- Repeat previously entered commands
- Open or quit Terminal on Mac
- Open Terminal
- Quit Terminal
- Quit a shell session
- 7 simple ways to open Terminal on Mac
- Open Terminal using Spotlight Search
- Open Terminal using Finder
- Open Terminal using the Applications folder
- Open Terminal using Launchpad
- Open Terminal using Siri
- Create a Terminal shortcut
- Terminal commands and tips
- Wrapping it up
- How to Launch GUI Applications from the Terminal
- Opening Mac OS X Applications from the Command Line
- Launching GUI Apps as root from the Command Line
- Creating Shell Aliases for Frequently Launched GUI Apps
- Related
- Enjoy this tip? Subscribe to our newsletter!
- Thank you!
- Related articles:
- 30 Comments
Execute commands and run tools in Terminal on Mac
You can use the command-line environment interactively by typing a command and waiting for a result, or you can use the shell to compose scripts that run without direct interaction.
Execute commands in the shell
In the Terminal app on your Mac, enter the complete pathname of the tool’s executable file, followed by any needed arguments, then press Return.
If a command is located in one of the shell’s known folders, you can omit path information when entering the command name. The list of known folders is stored in the shell’s PATH environment variable and includes the folders containing most command-line tools.
For example, to run the ls command in the current user’s home folder, enter the following at the command prompt, then press Return:
To run a command in the current user’s home folder, precede it with the folder specifier. For example, to run MyCommandLineProg , use the following:
To open an app, use the open command:
When entering commands, if you get the message command not found , check your spelling. Here’s an example:
Terminate commands
In the Terminal app on your Mac, click the Terminal window that is running the command you want to terminate.
This sends a signal that causes most commands to terminate.
Repeat previously entered commands
The commands you enter during a session are saved so you can repeat a previously used command without retyping it.
In the Terminal app on your Mac, press the Up Arrow key.
The last command you entered appears on the command line.
Continue pressing the Up Arrow key until you see the command you want, then press Return.
Источник
Open or quit Terminal on Mac
Each window in Terminal represents an instance of a shell process. The window contains a prompt that indicates you can enter a command. The prompt you see depends on your Terminal and shell preferences, but it often includes the name of the host you’re logged in to, your current working folder, your username and a prompt symbol. For example, if a user named michael is using the default zsh shell, the prompt appears as:
This indicates that the user named michael is logged in to a computer named MacBook-Pro, and the current folder is his home folder, indicated by the tilde (
Open Terminal
On your Mac, do one of the following:
Click the Launchpad icon in the Dock, type Terminal in the search field, then click Terminal.
In the Finder , open the /Applications/Utilities folder, then double-click Terminal.
Quit Terminal
In the Terminal app on your Mac, choose Terminal > Quit Terminal.
Quit a shell session
In the Terminal app on your Mac, in the window running the shell process you want to quit, type exit , then press Return.
This ensures that commands actively running in the shell are closed. If anything’s still in progress, a dialogue appears.
If you want to change the shell exit behaviour, see Change Profiles Shell preferences.
Источник
7 simple ways to open Terminal on Mac
Terminal is a handy tool for giving your Mac commands although many may be intimidated by it. After all, it’s not as easy as just typing in a sentence and your Mac responding. We have some articles listed below that can help you with common commands if you’re interested in learning to use Terminal or if you just want to enter a command or two.
Either way, before you can use it, you have to open it, right? There are various methods for opening it; here are seven simple ways to open Terminal on Mac.
Open Terminal using Spotlight Search
One of the quickest and easiest ways to open Terminal on Mac is with Spotlight Search.
1) If you have the Spotlight Search button in your menu bar, click it. Otherwise, you can use the keyboard shortcut Command + Space.
2) Type in “Terminal”.
3) You should see the Terminal application under Top Hit at the top of your results. Double-click it and Terminal will open.
Open Terminal using Finder
Open Finder or make sure that your menu bar is using Finder and not another application.
1) Click Go > Utilities from the menu bar.
2) In the Utilities folder that opens, double-click Terminal.
Open Terminal using the Applications folder
If you have a Finder window open, you can access Terminal from the Applications folder.
1) Select Applications from the left side.
2) Click the arrow to expand the Utilities folder.
3) Double-click Terminal.
If you have the Applications folder in your Dock like I do, you can open Terminal from there too.
1) Click Applications in your dock.
2) Select Utilities.
3) Choose Terminal.
Open Terminal using Launchpad
You can open Terminal using Launchpad two ways, depending on if you have organized Launchpad a different way or not.
By default, Launchpad contains a folder labeled Other that contains Terminal.
1) Open Launchpad from your Dock or with the keyboard shortcut Fn + F4.
2) Locate the Other folder and click.
3) Choose Terminal.
If you have arranged your Launchpad items differently and removed the Other folder, you can still find Terminal easily.
1) Open Launchpad from your Dock or with the keyboard shortcut Fn + F4.
2) Type “Terminal” into the search box at the top.
3) When the Terminal icon displays, click it.
Open Terminal using Siri
Thanks to a helpful comment from one of our readers, there is one more super simple to way to open Terminal on Mac; using Siri.
1) Click the Siri button from your menu bar or open Siri from your Applications folder.
2) Using your microphone, simply say “Open Terminal.”
Create a Terminal shortcut
If you decide that you want to start using Terminal more often, creating a shortcut for it in your Dock is convenient.
With the Terminal icon in your Dock already, from recently opening it, do the following.
1) Hold Control and click the Terminal icon in the Dock or right-click it.
2) Mouse over Options in the pop-up menu.
3) Click Keep in Dock.
Terminal commands and tips
As mentioned above, here are some of our articles with commands you can use for Terminal that may come in handy.
You can also head to the Terminal section of our website for additional tips and tutorials for Terminal.
Wrapping it up
Terminal is a terrific tool for doing things quickly on your Mac. And once you get the hang of it, and bookmark some useful commands, it’s not as intimidating anymore.
Have you tried to use Terminal yet or are you interested in learning more about it so that you can use it? Let us know your thoughts below and if you have any tips you’d like to share with our readers for using Terminal, feel free to comment!
Источник
How to Launch GUI Applications from the Terminal
We all know how to launch applications from the GUI with a double-click on the icon or clicking on the app in the Dock, and there are numerous ways to do so, and they’re all relatively speedy. If you spend a decent amount of time with the command line though, it’s nice to be able to launch Mac apps directly from there as well. Also, the Terminal has a fair share of applications that run in text based mode, but maybe you wanted to edit a text file in the OS X GUI app TextWrangler rather than the text based nano or vim.
We’re going to demonstrate how to launch any graphical Mac app from the command line of OS X, including how to open specific files from the command line with a GUI app, and how to edit and open those files with root access if it’s necessary.
Opening Mac OS X Applications from the Command Line
The Terminal command to launch OS X gui apps is appropriately called ‘open’ and here is how it works at it’s most simple:
open -a ApplicationName
That will open the defined app named “ApplicationName”.
But open is much more powerful than that. If you just type ‘open’ at the command prompt, you’ll return the basic help file with details on how to properly use the command with a variety of flags and syntax. While the open command exists in all versions of Mac OS X, the abilities vary somewhat depending on what version of OS X the Mac is running. Nonetheless, in modern releases this is what you’ll see:
In other words, example simple command syntax could look like the following, opening “ApplicationName” with the file located at the path ‘/file/to/open’:
open -a ApplicationName /file/to/open
You’ll note you don’t need the full path to the application name, but you would need the full path to a file name.
The usage is likely self explanatory to those who have experience in the command line environment, but for those who are new to the Terminal, don’t be too confused, it is easy to use and we’ll explain. For example, if you want to edit /etc/motd with TextWrangler to change your Message of the Day, but you hate the command line editors nano and vi, here is what you’d type:
$ open -a TextWrangler /etc/motd
Now you can edit these files in the familiar GUI. open is smart enough to know that when you apply the -a flag, you are launching an application so you don’t need to type in its full path. Obviously, it’ll still need the full path to the file you’re editing though.
There are many other usages for the open command rather than just editing text files, so use your imagination and get creative. open could be particularly useful to system administrators who utilize it in a shell script, perhaps to launch a specific GUI application at a scheduled time.
Also worth noting is that if you are launching an application with spaces in its name, you’ll want to add a backslash after each word, opening Adobe Photoshop CS would look like this:
$ open -a Adobe\ Photoshop\ CS
Launching GUI Apps as root from the Command Line
You can even open files with sudo by using the open command if you need to edit a file as root, for example:
sudo open -a TextEdit /tmp/magicfile
This will launch the target file into the desired application as root user, giving full root privileges to edit and modify the file, which is quite helpful for editing many system files. Of course, don’t modify any system file if you don’t know what you’re doing.
Creating Shell Aliases for Frequently Launched GUI Apps
So it’s kind of a pain in the butt to type a full command repeatedly, or to type out all that out over and over again, right? Well let’s make it easier by assigning an alias to an application that gets frequently launched. We’ll take the aforementioned Adobe Photoshop app as an example since the file name is lengthy, so here’s how we’ll do this with the Mac OS X default Bash shell:
First launch the profile or .bash_profile into a text editor:
Ignoring whatever else may be in this file (it could be empty also), add the following to a new line:
alias photoshop=»open -a Adobe\ Photoshop\ CS»
This creates an alias, so that the “open -a Adobe\ Photoshop CS” command is now shortened to simply ‘photoshop’. Save .profile, and you’re on your way! You can use the alias command in conjunction with open for virtually anything, just be sure to pick an alias to a command that doesn’t already exist.
The open command is really handy as you can see, if you have any other great uses for it in OS X, be sure to let us know in the comments.
Related
Enjoy this tip? Subscribe to our newsletter!
Get more of our great Apple tips, tricks, and important news delivered to your inbox with the OSXDaily newsletter.
Thank you!
You have successfully joined our subscriber list.
Related articles:
30 Comments
Thanks for this article – as a Late 2012 Mac Mini user, I have struggled to figure out how to configure X-Plane11 to run real time. I ran the benchmark:
open -a X-Plane.app –args –fps_test=1 –load_smo=Output/replays/test_flight_c4.fdr –pref:_is_ful_ALL=1 –pref:_x_res_full_ALL=1280 –pref:_y_res_full_ALL=720 –pref:_bpp_full_ALL=32
and got:
FRAMERATE TEST: time=93.5, frames=2162, fps=23.12
GPU LOAD: time=93.5, wait=5.7, load=6.1%
so I knew if I made my X-Plane settings 1280×720 windowed, I could get real-time performance, and it works!
How do I write it so that it opens a file, but not a specific file, one that a program could choose?
There is another way of dealing with spaces in this case.
Instead of:
open -a Adobe\ Photoshop\ CS
You could use:
open -a ‘Adobe Photoshop CS’
So, the alias for this would be:
alias photoshop=”open -a ‘Adobe Photoshop CS’ ”
Also, notice the space in the end of the alias (after the CS’ part). It allows you to do more with the command. Example:
Let’s say we got an alias for Chrome. It looks like this:
alias chrome=”open -a ‘Google Chrome’”
In the terminal you want to open a text file with Chrome. Let’s say it’s called ”mydocument.txt”. You will try this in the Terminal:
Which will return an error like this:
Unable to find application named ‘Google Chromemydocument.txt”
Using the alias here is the same as:
open -a ‘Google Chrome’mydocument.txt
So, instead of this we put a space in the alias:
Alias before: alias chrome=”open -a ‘Google Chrome’”
Alias after: alias chrome=”open -a ‘Google Chrome’ ”
Now, when using this space and open a file with the application Alias is equal to:
open -a ‘Google Chrome’ mydocument.txt
The result is that Chrome will open the file mydocument.txt in the browser. Of course, the application itself should be able to display the file.
The same can be used for commands like:
sudo
Allowing you to enable sudo on aliases.
So, the alias for sudo would be like this:
alias sudo=”sudo ”
In that way, you can use (just a example, there is almost no reason at all for this in real world use for Google Chrome):
sudo chrome
To break it down:
-> open -a
As described in the article, the command that will ”Open with the specified application”.
-> ‘Google Chrome’
The exact name of the application as displayed in the Finder without the .app extension.
-> mydocument.txt
The path to the file that will open. In this example, the file is located in the same working directory. But if i was to open a file located in the folder ”Text files from Chanderton” at the Desktop. it would look like this if i was to drag and drop the file in the Terminal after the alias name:
chrome /Users/YourUserName/Desktop/Text\ Files\ from\ Chanderton/mydocument.txt
or not using the application Alias:
open -a ‘Google Chrome’ /Users/YourUserName/Desktop/Text\ Files\ from\ Chanderton/mydocument.txt
—
For the ones that like things to be over the top. You can create the alias like this:
alias chrome=”say ‘Starting Chrome’ | open -a ‘Google Chrome’ ”
or:
alias chrome=”echo ‘🗣 Starting Chrome 👀 ‘; wait | say ‘Starting Chrome’; wait | echo ‘👍 Yeah!’; open -a ‘Google Chrome’ “
[…] X with root privileges, but it’s not just a matter of prepending sudo to the otherwise useful open command, because ‘open’ launches apps as the original user, with or without sudo. The solution […]
How do I also pass command line switches to the app? I’m trying to open VLC with the -v –color switches. (I saw them on the VLC wiki, maybe these are windows only options but the wiki doesn’t specify that.)
Hi
Thanks to you, I can now open my files in Preview using the command line. Now I need to “Save as” in Preview using the command line. Does anyone know how to do it?
Thanks!
Sofia
Try this for a “Save As” replacement in OS X Lion
Hi Matt
Thanks for your reply. but I need to “save as” or “export” from the command line.
I need to convert more than hundred images from .pdf to bmp and to eps and I want to do it in a script. For that, I would like to open these files in Preview and save them in the new format, everything from the command line. Is it possible to “save as” in Preview from the command line?
Thanks
Sofia
[…] command line users, use the “open” command to pass wildcards to ImageOptim for easy scripting and bulk image compression like […]
[…] your hard disk name for this walkthrough. Now here’s the interesting part, typically you can launch applications from the Terminal with the ‘open’ command, but the Lion Recovery drives have a stripped down set of […]
[…] Line, Mac OS X, Tips & Tricks – July 18th, 2011 – Leave a Comment Using the command line open tool, you can immediately launch any URL from the Terminal into the default web browser. The syntax […]
[…] tells the command to only open the file if the header was successfully downloaded. Using ‘open‘ will open httpheader.txt in the default GUI text editor, which is generally Text Edit, but […]
[…] application in Mac OS X with a little command line magic. Using the ‘open’ command to launch GUI apps from the Terminal, we can run a new instance of any app, even if it is already […]
so how do i open a folder in the terminal to have it open as a gui folder? (not cd command – that just opens it in the terminal itself)
for instance can i say
open /etc? and have the gui window pop up?
so open /etc would open /etc in the Finder
[…] osxdaily David Miller O’reilly wiki bash ss64 This entry was posted in bash, osx, terminal. Bookmark […]
[…] How to Launch GUI Applications from the Terminal – OS X Daily (tags: alias command bsd howto macosx terminal tip open apple launch opensource unix tips osx shell macos applications application commandline macintosh mac from gui article os guide) […]
[…] Come lanciare le applicazioni di Mac OS X dalla linea di comando (Terminale) How to Launch GUI Applications from the Terminal – OS X Daily. […]
anyone know how I can do adobe updates through the command line.? I want to send unix commands with ARD to adobe updater to install the updates.
a search by Pacifist (of the base.pkg and the bsd.pkg) on the osx leopard retail installer dvd turns up NO RESULT for a command named “open”!
are you sure that this command was available even in tiger?!
you really need to be more precise about the context of the ‘open’ command vis a vis the (bash) shell …
what are the prerequisites & dependencies that must already be setup in order – for instance – to run the ‘open’ command from the osx installer dvd?!
i have created a custom boot disk that adds an extra folder of diagnostic utilities to help troubleshooting … but none of those apps will run even when my local path already is located at the (new) special utility folder (ls sees the contents of the directory just fine).
i suspect that apple’s path info (on the bootable dvd) is locked down, so osx can not even see the ‘open’ command (because it is not part of the bsd userland that is loaded from the boot dvd) — if this is true, then i suppose it is just a matter of editing some config files (on the disk image) before burning another custom installer, correct?
If so, then it would be useful for you to articulate a flight-check/checklist of which files must be setup in what way in order to allow a given functionality under what circumstances!
obviously, my specific example is the one i am most interested in 🙂
ps: it should be noted that the reason i am want to launch specific apps /from the installer disc/ is precisely because i do not wish to complete the only type of installation that is available to me (in this case, unfortunately, a fresh install, which will wipe my current partition) … i have not backed it up yet (long story) but i want the chance now to dump everything on the NAS – alas, firewire target mode is not available because that port seems dead on my Mini 🙁 …
i dont know exactly what app will allow me to backup to the NAS (carbon copy cloner, disk utility, etc), but no matter which one i will need to use, i know i will need to use the ‘open’ command from a bash shell that has a default restriction on how much of the global path is visible to the bootable installer dvd!
i am sure i am not the only person who will be ever caught with a blown-up partition on a machine that cant use firewire target mode – so some clarification about the prereqs in the path environment variables would be super appreciated!
Источник