To make an alias for the Terminal in OS X, you can either put the aliases in.bashprofile or.bashrc. What is the difference between the two and why would I choose to put aliases in one and not the.
The Terminal app allows you to control your Mac using a command prompt. Why would you want to do that? Well, perhaps because you’re used to working on a command line in a Unix-based system and prefer to work that way. Terminal is a Mac command line interface. There are several advantages to using Terminal to accomplish some tasks — it’s usually quicker, for example. In order to use it, however, you’ll need to get to grips with its basic commands and functions. Once you’ve done that, you can dig deeper and learn more commands and use your Mac’s command prompt for more complex, as well as some fun, tasks.
Curated Mac apps that keep your Mac’s performance under control. Avoid Terminal commands, avoid trouble.Download Free
How to open Terminal on Mac
The Terminal app is in the Utilities folder in Applications. To open it, either open your Applications folder, then open Utilities and double-click on Terminal, or press Command - spacebar to launch Spotlight and type 'Terminal,' then double-click the search result.
You’ll see a small window with a white background open on your desktop. In the title bar are your username, the word 'bash' and the dimensions of the window in pixels. Bash stands for 'Bourne again shell'. There are a number of different shells that can run Unix commands, and on the Mac Bash is the one used by Terminal.
If you want to make the window bigger, click on the bottom right corner and drag it outwards. If you don’t like the black text on a white background, go to the Shell menu, choose New Window and select from the options in the list.
If Terminal feels complicated or you have issues with the set-up, let us tell you right away that there are alternatives. MacPilot allows to get access to over 1,200 macOS features without memorizing any commands. Basically, a third-party Terminal for Mac that acts like Finder.
For Mac monitoring features, try iStat Menus. The app collects data like CPU load, disk activity, network usage, and more — all of which accessible from your menu bar.
Basic Mac commands in Terminal
The quickest way to get to know Terminal and understand how it works is to start using it. But before we do that, it’s worth spending a little time getting to know how commands work. To run a command, you just type it at the cursor and hit Return to execute.
Every command is made up of three elements: the command itself, an argument which tells the command what resource it should operate on, and an option that modifies the output. So, for example, to move a file from one folder to another on your Mac, you’d use the move command 'mv' and then type the location of the file you want to move, including the file name and the location where you want to move it to.
Let’s try it.
Type cd ~/Documentsthen and press Return to navigate to your Home folder.
Type lsthen Return (you type Return after every command).
You should now see a list of all the files in your Documents folder — ls is the command for listing files.
To see a list of all the commands available in Terminal, hold down the Escape key and then press y when you see a question asking if you want to see all the possibilities. To see more commands, press Return.
Unix has its own built-in manual. So, to learn more about a command type man [name of command], where 'command' is the name of the command you want find out more about.
There are a few things you need to bear in mind when you’re typing commands in Terminal, or any other command-line tool. Firstly, every character matters, including spaces. So when you’re copying a command you see here, make sure you include the spaces and that characters are in the correct case.
You can’t use a mouse or trackpad in Terminal, but you can navigate using the arrow keys. If you want to re-run a command, tap the up arrow key until you reach it, then press Return. To interrupt a command that’s already running, type Control-C.
Commands are always executed in the current location. So, if you don’t specify a location in the command, it will run wherever you last moved to or where the last command was run. Use the cdcommand, followed by a directory path, like in Step 1 above, to specify the folder where you want a command to run.
There is another way to specify a location: go to the Finder, navigate to the file or folder you want and drag it onto the Terminal window, with the cursor at the point where you would have typed the path.
Here’s another example. This time, we’ll create a new folder inside your Documents directory and call it 'TerminalTest.'
Open a Finder window and navigate to your Documents folder.
Type cd and drag the Documents folder onto the Terminal window.
Now, type mkdir 'TerminalTest'
Go back to the Finder, open Text Edit and create a new file called 'TerminalTestFile.rtf'. Now save it to the TerminalTest folder in your Documents folder.
In the Terminal window, type cd ~/Documents/TerminalTest then Return. Now type lsand you should see 'TerminalTestFile' listed.
To change the name of the file, type this, pressing Return after every step:
mv TerminalTestFile TerminalTestFile2.rtf
That will change the name of the file to 'TerminalTestFile2'. You can, of course, use any name you like. The mv command means 'move' and you can also use it to move files from one directory to another. In that case, you’d keep the file names the same, but specify another directory before typing the the second instance of the name, like this:
mv ~/Documents/TerminalTest TerminalTestFile.rtf ~/Documents/TerminalTest2 TerminalTestFile.rtf
More advanced Terminal commands
Terminal can be used for all sorts of different tasks. Some of them can be performed in the Finder, but are quicker in Terminal. Others access deep-rooted parts of macOS that aren’t accessible from the Finder without specialist applications. Here are a few examples.
Copy files from one folder to another
In a Terminal window, type ditto [folder 1] [folder 1] where 'folder 1' is the folder that hosts the files and 'folder 2' is the folder you want to move them to.
To see the files being copied in the Terminal window, type -v after the command.
Download files from the internet
You’ll need the URL of the file you want to download in order to use Terminal for this.
curl -O [URL of file you want to download]
If you want to download the file to a directory other than your Downloads folder, replace ~/Downloads/ with the path to that folder, or drag it onto the Terminal window after you type the cd command.
Change the default location for screenshots
If you don’t want macOS to save screenshots to your Desktop when you press Command-Shift-3, you can change the default location in Terminal
defaults write com.apple.screencapture location [path to folder where you want screenshots to be saved]
Change the default file type for screenshots
By default, macOS saves screenshots as .png files. To change that to .jpg, do this:
defaults write com.apple.screencapture type JPG
Delete all files in a folder
The command used to delete, or remove, files in Terminal is rm. So, for example, if you wanted to remove a file in your Documents folder named 'oldfile.rtf' you’d use cd ~/Documents to go to your Documents folder then to delete the file. As it stands, that will delete the file without further intervention from you. If you want to confirm the file to be deleted, use -i as in rm -i oldfile.rtf
To delete all the files and sub-folders in a directory named 'oldfolder', the command is rm -R oldfolder and to confirm each file should be deleted, rm -iR oldfolder
Just because you can use Terminal to delete files on your Mac, doesn’t mean you should. It’s a relatively blunt instrument, deleting only those files and folders you specify.
Another way to free up space
If your goal in removing files or folders is to free up space on your Mac, or to remove junk files that are causing your Mac to run slowly, it’s far better to use an app designed for the purpose. CleanMyMac X is one such app.
It will scan your Mac for files and recommend which ones you can delete safely, as well as telling you how much space you’ll save. And once you’ve decided which files to delete, you can get rid of them in a click. You can download CleanMyMac here.
As you can see, while Terminal may look scary and seem like it’s difficult to use, it really isn’t. The key is learning a few commands, such as those we’ve outlined above, and getting to know the syntax for those commands.
However, you should be careful when using Terminal, it’s a powerful tool that has deep access to your Mac’s system files. Check commands by googling them if you’re not sure what they do. And if you need to delete files to save space, use an app like CleanMyMac X to do it. It’s much safer!
These might also interest you:
In Visual Studio Code, you can open an integrated terminal, initially starting at the root of your workspace. This can be convenient as you don't have to switch windows or alter the state of an existing terminal to perform a quick command-line task.
To open the terminal:
- Use the ⌃` (Windows, Linux Ctrl+`) keyboard shortcut with the backtick character.
- Use the View > Terminal menu command.
- From the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)), use the View: Toggle Integrated Terminal command.
Note: You can still open an external shell with the ⇧⌘C (Windows, Linux Ctrl+Shift+C) keyboard shortcut if you prefer to work outside VS Code.
Managing multiple terminals
You can create multiple terminals open to different locations and easily navigate between them. Terminal instances can be added by clicking the plus icon on the top-right of the TERMINAL panel or by triggering the ⌃⇧` (Windows, Linux Ctrl+Shift+`) command. This action creates another entry in the drop-down list that can be used to switch between them.
Remove terminal instances by pressing the trash can button.
Tip: If you use multiple terminals extensively, you can add key bindings for the
kill commands outlined in the Key Bindings section to allow navigation between them using only the keyboard.
You can also split the terminal by triggering the ⌘ (Windows, Linux Ctrl+Shift+5) command or via the right click context menu.
When focusing a split terminal pane, you can move focus and resize using one of the following commands:
|⌥⌘← (Windows, Linux Alt+Left)||Focus Previous Pane|
|⌥⌘→ (Windows, Linux Alt+Right)||Focus Next Pane|
|⌃⌘← (Windows , Linux Ctrl+Shift+Left)||Resize Pane Left|
|⌃⌘→ (Windows , Linux Ctrl+Shift+Right)||Resize Pane Right|
|⌃⌘↑ (Windows, Linux )||Resize Pane Up|
|⌃⌘↓ (Windows, Linux )||Resize Pane Down|
The shell used defaults to
$SHELL on Linux and macOS, PowerShell on Windows 10 and cmd.exe on earlier versions of Windows. These can be overridden manually by setting
terminal.integrated.shell.* in user settings. Arguments can be passed to the terminal shell using the
terminal.integrated.shellArgs.* user settings.
Note: For enhanced security, such settings can only be defined in user settings and not at workspace scope.
For Windows there is a convenient shell selector located inside the terminal dropdown that lets you choose between several detected shells including Command Prompt, PowerShell, PowerShell Core, Git Bash and WSL Bash. The Terminal: Select Default Shell command is also available through the Command Palette if you prefer to access it there.
Just like on other platforms you can fine tune the exact executable used in your settings file, for example:
Note: To be used as an integrated terminal, the shell executable must be a console application so that
stdin/stdout/stderr can be redirected.
Tip: The integrated terminal shell is running with the permissions of VS Code. If you need to run a shell command with elevated (administrator) or different permissions, you can use platform utilities such as
runas.exe within a terminal.
You can pass arguments to the shell when it is launched.
For example, to enable running bash as a login shell (which runs
.bash_profile), pass in the
-l argument (with double quotes):
Bash For Mac Download
cwd terminal settings all support resolving variables:
Terminal display settings
You can customize the integrated terminal font and line height with the following settings:
The View: Toggle Integrated Terminal command is bound to ⌃` (Windows, Linux Ctrl+`) to quickly toggle the integrated terminal panel in and out of view.
Below are the keyboard shortcuts to quickly navigate within the integrated terminal:
|⌃` (Windows, Linux Ctrl+`)||Show integrated terminal|
|⌃⇧` (Windows, Linux Ctrl+Shift+`)||Create new terminal|
|⌥⌘PageUp (Windows Ctrl+Alt+PageUp, Linux Ctrl+Shift+Up)||Scroll up|
|⌥⌘PageDown (Windows Ctrl+Alt+PageDown, Linux Ctrl+Shift+Down)||Scroll down|
|PageUp (Windows, Linux Shift+PageUp)||Scroll page up|
|PageDown (Windows, Linux Shift+PageDown)||Scroll page down|
|⌘Home (Windows Ctrl+Home, Linux Shift+Home)||Scroll to top|
|⌘End (Windows Ctrl+End, Linux Shift+End)||Scroll to bottom|
|⌘K (Windows, Linux )||Clear the terminal|
Other terminal commands are available and can be bound to your preferred keyboard shortcuts, such as:
workbench.action.terminal.focus: Focus the terminal. This is like toggle but focuses the terminal instead of hiding it, if it is visible.
workbench.action.terminal.focusNext: Focuses the next terminal instance.
workbench.action.terminal.focusPrevious: Focuses the previous terminal instance.
workbench.action.terminal.focusAtIndexN: Focuses the terminal at index N (N=1-9)
workbench.action.terminal.kill: Remove the current terminal instance.
workbench.action.terminal.runSelectedText: Run the selected text in the terminal instance.
workbench.action.terminal.runActiveFile: Run the active file in the terminal instance.
Copy & Paste
The keybindings for copy and paste follow platform standards:
- Linux: Ctrl+Shift+C and Ctrl+Shift+V
- macOS: Cmd+C and Cmd+V
- Windows: Ctrl+C and Ctrl+V
Right click behavior
The right click behavior differs based on the platform:
- Linux: Show the context menu.
- macOS: Select the word under the cursor and show the context menu.
- Windows: Copy and drop selection if there is a selection, otherwise paste.
This can be configured using the
Forcing key bindings to pass through the terminal
While focus is in the integrated terminal, many key bindings will not work as the keystrokes are passed to and consumed by the terminal itself. There is a hardcoded list of commands, which skip being processed by the shell and instead get sent to the VS Code keybinding system. You can customize this list with the
terminal.integrated.commandsToSkipShell setting. Commands can be added to this list by adding the command name to the list, and removed by adding the command name to the list prefixed with a
Look at the setting details to see the complete list of default commands.
The Integrated Terminal has basic find functionality which can be triggered with ⌘F (Windows, Linux Ctrl+F).
If you want Ctrl+F to go to the shell instead of launching the Find widget on Linux and Windows, you will need to remove the keybinding like so:
Run Selected Text
To use the
runSelectedText command, select text in an editor and run the command Terminal: Run Selected Text in Active Terminal via the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)):
The terminal will attempt to run the selected text.
If no text is selected in the active editor, the line that the cursor is on is run in the terminal.
Send text from a keybinding
workbench.action.terminal.sendSequence command can be used to send a specific sequence of text to the terminal, including escape sequences. This enables things like sending arrow keys, enter, cursor moves, etc. The example below shows the sort of things you can achieve with this feature, it jumps over the word to the left of the cursor (Ctrl+Left arrow) and presses backspace:
This feature supports variable substitution.
Note that the command only works with the
u0000 format for using characters via their character code (not
x00). You can read more about these hex code and the sequences terminals work with on the following resources:
Rename terminal sessions
Integrated Terminal sessions can now be renamed using the Terminal: Rename (
workbench.action.terminal.rename) command. The new name will be displayed in the terminal selection drop-down.
Open at a specific folder
By default, the terminal will open at the folder that is opened in the Explorer. The
terminal.integrated.cwd setting allows specifying a custom path to open instead:
Split terminals on Windows will start in the directory that the parent terminal started with. On macOS and Linux, split terminals will inherit the current working directory of the parent terminal. This behavior can be changed using the
There are also extensions available that give more options such as Terminal Here.
Changing shell for tasks and debug
You can set
terminal.integrated.automationShell.<platform> to override the shell and shell args used by tasks and debug:
Changing how the terminal is rendered
By default, the integrated terminal will render using multiple
<canvas> elements which are better tuned than the DOM for rendering interactive text that changes often. However, Electron/Chromium are slower at rendering to canvas on some environments so VS Code also provides a fallback DOM-renderer experience. VS Code will try to detect slow performance and give you the option to change via a notification. You can also change the rendering directly by setting
terminal.integrated.rendererType in your user or workspace settings.
Something else that might improve performance is to ignore Chromium's GPU disallow list by launching VS Code with
The basics of the terminal have been covered in this document, read on to find out more about:
- Tasks - Tasks let you integrate with external tools and leverage the terminal heavily.
- Mastering VS Code's Terminal - An external blog with plenty of power user tips for the terminal.
- Explore the rest of the terminal commands by browsing your keybindings.json file within VS Code.
Can I use the integrated terminal with the Windows Subsystem for Linux?
Yes, you can select the Windows Subsystem for Linux (WSL) bash shell as your terminal default. If you have WSL enabled (through Windows Features), you can select WSL Bash from the terminal Select Default Shell drop down. See Developing in WSL for details on working in WSL and the Remote - WSL extension.
Why is VS Code shortcut X not working when the terminal has focus?
Currently the terminal consumes many key bindings, preventing Visual Studio Code from reacting to them. Some examples are F1 to open the Command Palette and Ctrl+P for Quick Open on Linux and Windows. This is necessary as various terminal programs and/or shells may respond to these key bindings themselves. You can use the
terminal.integrated.commandsToSkipShell setting to prevent specific key bindings from being handled by the terminal.
Integrated terminal exited with code 1 on Windows 10
This can happen if you run VS Code in compatibility mode which may be turned on automatically if you have upgraded Windows. You can change this by right-clicking the executable and selecting properties, then uncheck 'Run this program in compatibility mode' in the compatibility tab.
Can I use Cmder's shell with the terminal on Windows?
Yes, to use the Cmder shell in VS Code, you need to add the following settings to your
You may refer to Cmder's wiki for more information.
PowerShell on macOS is complaining about a '-l' argument, how do I fix it?
When configuring the integrated terminal to use PowerShell on macOS you may hit this error complaining about a
'-l' argument. To fix this you will need to override the shell args setting as it defaults to
['-l'] to run login shells by default (for bash/zsh/etc.).
How can I change my default Windows terminal back to PowerShell?
If you want to put the default Integrated Terminal shell back to the default (PowerShell on Windows), you can remove the shell override from your User Settings (⌘, (Windows, Linux Ctrl+,)).
For example, if you have set your default terminal to bash, you will find
terminal.integrated.shell.windows in your
settings.json pointing to your bash location.
Remove the entry to use the built-in VS Code default or set it to another shell executable path.
Git Bash For Mac Terminal
Why is the terminal not working when running the 32-bit Windows client on 64-bit Windows?
The easy fix for this is to use the 64-bit version. If you must use the 32-bit version you need to use the
sysnative path when configuring your paths instead of
Why is Cmd+k/Ctrl+k not clearing the terminal?
Normally Cmd+k/Ctrl+k clears the terminal on macOS/Windows, but this can stop working when chord keybindings are added either by the user or extensions. The Cmd+k/Ctrl+k keybindings rely on the VS Code keybinding priority system which defines which keybinding is active at any given time (user > extension > default). In order to fix this, you need to redefine your user keybinding which will have priority, preferably at the bottom of your user
Why is nvm complaining about a prefix option when the Integrated Terminal is launched?
nvm (Node Version Manager) users often see this error for the first time inside VS Code's Integrated Terminal:
This is mostly a macOS problem and does not happen in external terminals. The typical reasons for this are the following:
npmwas globally installed using another instance of
nodewhich is somewhere in your path (such as
- In order to get the development tools on the
$PATH, VS Code will launch a bash login shell on start up. This means that your
~/.bash_profilehas already run and when an Integrated Terminal launches, it will run another login shell, reordering the
$PATHpotentially in unexpected ways.
To resolve this issue, you need to track down where the old
npm is installed and remove both it and its out of date node_modules. You can do this by finding the
nvm initialization script and running
which npm before it runs, which should print the path when you launch a new terminal.
Once you have the path to npm, you can find the old node_modules by resolving the symlink by running a command something like this:
This will give you the resolved path at the end:
From there, removing the files and relaunching VS Code should fix the issue:
Can I use Powerline fonts in the Integrated Terminal?
Yes, you can specify Powerline fonts with the
Note that you want to specify the font family, not an individual font like Meslo LG M DZ Regular for Powerline where Regular is the specific font name.
How do I configure zsh on macOS to jump words with Ctrl+Left/Right arrow?
By default, Ctrl+Left/Right arrow will jump words in bash. You can configure the same for zsh by adding these keybindings:
How do I fix the error 'ConnectNamedPipe failed: Windows error 232'
This error can occur due to anti-virus software intercepting winpty from creating a pty. To workaround this error, you can exclude the following file from your anti-virus scanning:
How do I fix when a terminal exits with error code 3221225786 on Windows?
This happens when you have legacy console mode enabled in conhost's properties. To change this, open
cmd.exe, right click the title bar, go to Properties and under the Options tab, uncheck Use legacy console.
Why is my terminal showing a multi-colored triangle or a completely black rectangle?
Mac Update Bash
The terminal can have problems rendering in some environments, for example you might see a big multi-colored triangle instead of text. This is typically caused by driver/VM graphics issues and the same also happens in Chromium. You can work around these issues by launching
code with the
--disable-gpu flag or by using the setting
'terminal.integrated.rendererType': 'dom' to avoid using the canvas in the terminal.