Mac终端如何修改默认启动目录?(macOS 10.12.4)
Hey there! Let's get your Terminal to open directly to your coding folder on the desktop—your earlier attempt had a small misstep, so let's break this down clearly.
Why Your Previous Attempt Didn't Work
When you set "Shell opens with command" to cd desktop/coding, you told Terminal to run only that single command and then exit immediately. There's no interactive shell launched after the cd completes, which is why you saw "process done" and couldn't type anything. That setting is designed for one-off non-interactive commands, not configuring your default shell environment.
Solution 1: Use Terminal's Built-in Preferences (Easiest)
This is the simplest way to set a default working directory:
- Open Terminal, then go to the top menu bar and select Terminal > Preferences (or press
Cmd + ,). - Switch to the Profiles tab (the icon that looks like a user profile).
- In the left sidebar, select your default profile (usually "Basic" unless you've customized it).
- Go to the General sub-tab.
- Under the "Working Directory" section, select Custom folder, then click the Choose button. Navigate to
~/Desktop/coding(make sure you pick the exact folder) and select it. - Close the Preferences window, then quit and restart Terminal—it should open directly to your coding folder now.
Solution 2: Modify Your Shell's Startup File (More Flexible)
If you want more control (like running other commands when Terminal starts), edit your shell's configuration file:
- Open Terminal (it'll start in your home directory for now).
- Type this command to open your bash profile in the nano text editor:
nano ~/.bash_profile - At the bottom of the file, add this line (using the absolute path avoids path-related issues):
cd ~/Desktop/coding - Press
Ctrl + Oto save the file, hitEnterto confirm the filename, thenCtrl + Xto exit nano. - To make the change take effect immediately, run:
Or just quit and restart Terminal—next time it opens, you'll land right in your coding folder.source ~/.bash_profile
Either method should solve your problem—pick whichever feels more comfortable for you!
内容的提问来源于stack exchange,提问作者malmeren

