zsh killing some commands but not others

I recently upgraded my laptop to 12.7. Since then, the terminal hasn't been working for me. Upon opening the terminal, I see the following two lines:

zsh: killed   mkdir -m 700 -p "$SHELL_SESSION_DIR"

zsh: killed   


Using commands such as ls, mkdir also results in zsh: killed ls or zsh: killed mkdir. This is the case with a few other commands but notably not homebrew or git. I've had homebrew and git for a long time and I don't think those are the issue since those commands work. In addition commands such as cd and echo also work. Can someone help me figure out how to make my terminal work again?

MacBook Pro 14″, macOS 12.7

Posted on Sep 25, 2023 1:54 PM

Reply

Similar questions

15 replies
Sort By: 

Sep 25, 2023 2:39 PM in response to dp1018

Quit Terminal.app, temporarily rename your zsh login files using Finder, and try launching Terminal.app again.


Use the Command-Shift-Period toggle in Finder to enable hidden-file viewing, then in your home directory temporarily rename the following files:


  • .zshrc
  • .zlogin
  • .zprofile
  • .zshenv


You may or may not have some or all of those scripts present.


Then try launching Terminal.app again.


If that resolves the immediate error, debugging the contents of one or more of your zsh login scripts is next.

Reply

Sep 25, 2023 2:30 PM in response to dp1018

Did you install Oh my Zsh! or anything else before this problem occurred? I have seen some instances, but not my own, where the installation of homebrew wreaks havoc on a .zshrc file. That Oh My Zsh! package does add more craziness to an otherwise normal Zsh installation. I purposely do not install it.


When you state that cd and echo work, it is because they are Zsh shell built-in commands. This leads me to wonder about your PATH configuration where /bin/mkdir is not being found.


I never formally created the $SHELL_SESSION_DIR, which is ~/.zsh_sessions, and yet it is present here, but showing that last entry as Sept 24. In my ~/.zshrc, I have export SHELL_SESSIONS_DISABLE=1, so don't know why that dir exists. Its permissions are 600 or (-rw-------). Not having that set to 700 (-rwx------) for a directory means you cannot search in ~/.zsh_sessions.

Reply

Sep 25, 2023 2:35 PM in response to VikingOSX

I haven't installed Oh my Zsh before. I did install docker which caused kernel panic and my laptop to crash 3 times before I just upgraded MacOS to get Docker working.


On the PATH note, when I do which mkdir or which ls (which both do not work), the path is /usr/local/bin/mkdir and /usr/local/bin/ls.


I can try to poke around in the .zsh files but I also tried /bin/zsh --no-rcs, which still gave the errors

Reply

Sep 25, 2023 2:51 PM in response to MrHoffman

I tried this but it did not work. I was able to find the .zshrc and .zprofile pages but the commands still ended up getting killed. One thing that I found interesting was that after editing the .zshrc file to update the path from: export PATH=/usr/local/bin/:PATH to export PATH=/bin:$PATH, the ls, mkdir commands work. However, the top line (zsh: killed   mkdir -m 700 -p "$SHELL_SESSION_DIR") still shows up. Also, since it looks like there are two versions of ls, I did 'where ls' and got

/bin/ls

/usr/local/bin/ls

/bin/ls

I've never thought to do where for a simple command so I'm not sure if this is common behavior

Reply

Sep 25, 2023 3:02 PM in response to VikingOSX

I was trying to install docker yesterday through homebrew and one of the commands I entered was along the lines of brew install docker virtualbox if I recall correctly. Could this have been the reason for the issue I am facing? I was able to set the path manually by putting this line in .zshrc: export PATH=/bin:$PATH. However, I am still getting the 2 lines on top when I open the terminal.

zsh: killed   mkdir -m 700 -p "$SHELL_SESSION_DIR"

zsh: killed  

Reply

Sep 25, 2023 3:06 PM in response to MrHoffman

I removed Homebrew by using the uninstall script that they provide but I'm still running into the issue. It seems like so far the only thing that has let me enter commands is changing the path variable in the .zshrc file. This is an Apple Silicon Mac, the M1 pro. When I use where ls I get this:

/bin/ls

/usr/local/bin/ls

/bin/ls

However when I cd into /bin, I only see one copy of ls, same for mkdir

Reply

Sep 25, 2023 5:23 PM in response to dp1018

Does the issue here reproduce in a newly-created and wholly different login?


What is in your PATH?


Use the file command on each of the images that re having issues, and confirm those are for Apple silicon and not Intel. Here is what I would expect (a universal binary with both architectures), but some of what homebrew installs can be architecture-specific:


$ file /bin/ls
/bin/ls: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e]
/bin/ls (for architecture x86_64):	Mach-O 64-bit executable x86_64
/bin/ls (for architecture arm64e):	Mach-O 64-bit executable arm64e
$ 


Check each copy of the executable file in the path, if there are multiple different files within the path.


I would not expect homebrew will completely uninstall itself without leaving some remnants. Local PATH settings possibly among those remnants.



Reply

Sep 25, 2023 7:38 PM in response to dp1018

dp1018 wrote:

I removed Homebrew by using the uninstall script

As far as I have been able to determine from what people post on this forum, Homebrew cannot be uninstalled. You have to erase the hard drive and reinstall the operating system.


Of course, in theory, it should be possible to remove Homebrew. But people tend to install Homebrew to avoid dealing with complex Unix configuration issues. That's all well and good until there is a problem. It seems like any system, Xcode, or Xcode command line upgrade will break it. And then, people come here and ask why basic commands have suddenly stopped working after 30 years. It is only after several questions and replies that Homebrew inevitably shows up.


So I don't know what to tell you. Your command-line environment is corrupted. You've attempted to uninstall Homebrew. Maybe that deleted some Homebrew files. Maybe not. Apparently it did not put your system configuration files back to the way they were, or the way they should have been, after Homebrew modified them. What to do now? Erase the hard drive and reinstall the operating system? Check out some old Unix books from the library and figure it out on your own? While the macOS operating system is technically unix, it is significantly different from other unix variants and from Linux. It is constantly being updated and there is no current, up-to-date reference or documentation. You would have to buy a new Mac, learn how the command line environment works there, and then you might be able to fix the old Mac. And maybe that won't work because the new Mac will be running macOS 13.6 or 14.0 and it won't be like your old 12.7. Homebrew is the gift that keeps on giving.

Reply

Sep 25, 2023 8:11 PM in response to MrHoffman

I did file /bin/ls and I got

/bin/ls: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64
- Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e
- Mach-O 64-bit executable arm64e]
/bin/ls (for architecture x86_64):	Mach-O 64-bit executable x86_64
/bin/ls (for architecture arm64e):	Mach-O 64-bit executable arm64e

I also did file /usr/local/bin/ls and I got

/usr/local/bin/ls: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64
- Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e
- Mach-O 64-bit executable arm64e]
/usr/local/bin/ls (for architecture x86_64):	Mach-O 64-bit executable x86_64
/usr/local/bin/ls (for architecture arm64e):	Mach-O 64-bit executable arm64e

It looks like the binary is for both architectures. I tried creating a new user with admin priviledges but that user also runs into the same issue. The only thing that has been able to help me so far is by adding the following line to .zshrc

export PATH=/bin:$PATH

However, this has only let me acutally use commands such as ls, mkdir, cat again. When I open the zsh terminal I am still greeted by the following lines:

Last login: Mon Sep 25 19:02:09 on ttys000
zsh: killed     mkdir -m 700 -p "$SHELL_SESSION_DIR"
zsh: killed
Reply

Sep 25, 2023 8:11 PM in response to MrHoffman

I did file /bin/ls and I got

/bin/ls: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64
- Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e
- Mach-O 64-bit executable arm64e]
/bin/ls (for architecture x86_64):	Mach-O 64-bit executable x86_64
/bin/ls (for architecture arm64e):	Mach-O 64-bit executable arm64e

I also did file /usr/local/bin/ls and I got

/usr/local/bin/ls: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64
- Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e
- Mach-O 64-bit executable arm64e]
/usr/local/bin/ls (for architecture x86_64):	Mach-O 64-bit executable x86_64
/usr/local/bin/ls (for architecture arm64e):	Mach-O 64-bit executable arm64e

It looks like the binary is for both architectures. I tried creating a new user with admin priviledges but that user also runs into the same issue. The only thing that has been able to help me so far is by adding the following line to .zshrc

export PATH=/bin:$PATH

However, this has only let me acutally use commands such as ls, mkdir, cat again. When I open the zsh terminal I am still greeted by the following lines:

Last login: Mon Sep 25 19:02:09 on ttys000
zsh: killed     mkdir -m 700 -p "$SHELL_SESSION_DIR"
zsh: killed
Reply

Sep 25, 2023 8:51 PM in response to dp1018

Yes, and you looked at ls. Niow what about that mkdir?


To display your path:

% echo $PATH

or

% print "%s\n" "$PATH"

Each location in the list—where the shell looks for commands or scripts—is delimited by a colon.


When I issue the following where, I get one response, and the output of file command shows as two arcjitectures and universal. If yours is not, or there is some other issue with the command, you may well get an immediate crash.

% where mkdir
/bin/mkdir
% file /bin/mkdir
/bin/mkdir: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e]
/bin/mkdir (for architecture x86_64):	Mach-O 64-bit executable x86_64
/bin/mkdir (for architecture arm64e):	Mach-O 64-bit executable arm64e
Reply

Sep 26, 2023 5:51 PM in response to MrHoffman

To provide an update, I was able to update the .zshrc file to set the path to /bin:$PATH and that let me use the commands again. Then, I noticed by doing 'which ls' and 'where ls' there was another instance of ls in /usr/local/bin as well as the normal /bin. I did rm on this and a few others, including mkdir in /usr/local/bin. This resulted in the opening error on the terminal to simply be:

zsh: killed     

However, I might be imagining this, but the terminal app does take a half second longer to start up. I'm not sure if it's the case but it looks like it is calling quite a few processes before finally allowing me to type commands

Reply

Sep 26, 2023 6:05 PM in response to dp1018

another update. I did where node and I had a weird path that didn't look right so I did an rm -r on it. This was my command:

 rm -r /Users/my_name/.nvm

After this it doesn't look like there are any issues with my terminal anymore. If anyone in the future has this problem it seems to be a path issue so first fix your .zshrc file to just and your access to commands should come again. Then rm everything that is a duplicate in /usr/local/bin. I also had to remove the .nvm folder which held node but I can just download that again later.

Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

zsh killing some commands but not others

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.