409

I have the Atom editor and was wondering how you can open a file or folder from the terminal in Atom. I am using a Mac. I am looking for a way to do this:

atom . (opens folder)

atom file.js (opens file)

atom (opens editor)

Is this possible and how do I set it up?

Flip
  • 4,701
  • 5
  • 32
  • 63
Anders
  • 9,518
  • 7
  • 25
  • 34

18 Answers18

715

With the Atom editor open, in the menu bar:

Click Atom >> Install Shell Commands

atom-add-shell-commands

You should expect to see:

atom-commands-installed

Potentially restart your terminal. (I did just out of habit, not sure if you need to)

nelsonic
  • 25,667
  • 19
  • 83
  • 109
shaheenery
  • 7,980
  • 2
  • 14
  • 13
  • 21
    What happened to me was that `atom` and `apm` symlinks were pointing to the Downloads folder from where I ran Atom for the first time. Then after moving Atom to the applications folder the symlinks were broken and the Install Shell Command option was not able to notice it. What I had to do was to remove the symlinks and then select the Install Shell Commands from the Atom menu. There was no need to restart the console as the `atom` command worked immediately after selecting the option. I ran `sudo rm /usr/local/bin/atom` and `sudo rm /usr/local/bin/apm` from a terminal to remove the symlinks – Jonathan Morales Vélez May 24 '14 at 15:41
  • 7
    Turned out you don't need to restart terminal. – AsyncMoksha Feb 25 '15 at 00:11
  • My computer was getting mixed up with XCODE and I had to restart and that fixed the problem. – Asher Jul 29 '15 at 15:43
  • This command only works if I don't restart my MacBook Pro after `Install Shell Commands` – Brian Jul 06 '17 at 08:42
  • This should be the answer – Chipe Feb 03 '18 at 20:22
  • For me, after removing the symlinks and trying ``Install Shell Commands`` again, it shows: ``The shell commands `undefined` and `undefined` are installed``. But after running it a second time, then it shows ``Atom`` and ``apm``. – Juha Untinen Mar 05 '19 at 09:35
  • rather than restart your terminal, you should be able to pickup the new commands (installed on your PATH) using `rehash` or `hash -r` – Gedge Apr 10 '19 at 10:47
  • atom . stopped working for me. I ran an atom update and 'Atom Menu bar' -> 'Install Shell Commands' and that did the trick. I wish this would show as the top answer. – Neal Parker Aug 03 '20 at 15:50
549

When Atom installs it automatically creates a symlink in your /usr/local/bin. However in case it hasn't, you can create it yourself on your Mac

ln -s /Applications/Atom.app/Contents/Resources/app/atom.sh /usr/local/bin/atom

Now you can use atom folder_name to open a folder and atom file_name to open a file.

Jesvin Vijesh S
  • 439
  • 4
  • 22
  • 37
    If you get "File exists" and the Atom command still dose not work just delete it and type the command over again. – Anders Mar 14 '14 at 09:34
  • 1
    When I do this, it continues to run in the terminal. Is there a way to be able to close the terminal after the command? – jhamm Apr 01 '14 at 20:05
  • @jhamm sorry I don't understand what you mean. Just go ahead and close the terminal, it doesn't affect Atom in any way. –  Apr 02 '14 at 09:55
  • When I close the terminal, then my Atom editor closes down too. It is like there is some process running in the editor still. – jhamm Apr 02 '14 at 12:37
  • 104
    Doesn't work. All input in Atom editor is sent to the terminal session that opened the Atom app. I solved the issue by choosing "Install Shell Commands" under the "Atom" menu. – Ryan Apr 16 '14 at 15:08
  • @jhamm try appending "&" so it would be `atom &` – JorgeArtware May 20 '14 at 15:03
  • I used this, then enter `atom .` in the terminal and no issue at all. – Link14 Sep 17 '15 at 05:18
  • This is way faster then the default script on my Mac: `alias atom='open -a Atom'` – Koen Bok Mar 25 '16 at 14:19
  • First I tried "Install Shell Commands" in Atom menu. It returned an error saying it couldn't create a new directory. I used user328's method and it worked perfectly. – PencilCrate Apr 29 '16 at 20:34
  • 1
    You might need to create the `/usr/local/bin/` directory with `sudo mkdir /usr/local/bin/` and use `sudo` for `ln` like `sudo ln -s /Applications/Atom.app/Contents/Resources/app/atom.sh /usr/local/bin/atom` – wieczorek1990 Jul 20 '16 at 16:36
  • i had to delete the link itself and also add /usr/local/bin to my path. also i moved atom to the applications folder. – j2emanue Jun 05 '17 at 09:13
  • `atom .` will open the current directory. – Dror Jun 23 '17 at 05:56
  • I open atom via application and then the command works. But I wanted it to open without having an instance of atom open. The following method doesn't work for me. – Saras Arya Aug 04 '17 at 07:43
20

Roll your own with @Clockworks solution, or in Atom, choose the menu option Atom > Install Shell Commands. This creates two symlinks in /usr/local/bin

apm -> /Applications/Atom.app/Contents/Resources/app/apm/node_modules/.bin/apm
atom -> /Applications/Atom.app/Contents/Resources/app/atom.sh

The atom command lets you do exactly what you're asking. apmis the command line package manager.

thomax
  • 7,735
  • 3
  • 44
  • 61
15

For Windows 7 x64 with default Atom installation add this to your PATH

%USERPROFILE%\AppData\Local\atom\app-1.4.0\resources\cli

and restart any running consoles

(if you don't find Atom there - right-click Atom icon and navigate to Target)

enter image description here

sbedulin
  • 3,413
  • 21
  • 30
  • 3
    OP is on Mac. I guess he requires a solution specific to Mac only – Ozil Jul 29 '16 at 15:31
  • 13
    I agree, but since the word "Mac" is not in the title or tags, it appears in search for everyone, hence may be helpful for Windows users. – sbedulin Jul 29 '16 at 17:14
  • 2
    If you don't want to bind this to a specific release, just use the bin folder: %USERPROFILE%\AppData\Local\atom\bin – fuma Nov 29 '16 at 13:57
  • 2
    @sbedulin OSX appears in the title as well a question tag. – Ozil Mar 19 '17 at 20:39
  • 1
    The question has been edited, but I'm not going to remove the answer util it's helpful for others (personally I'm against editing questions which are 3 years old). – sbedulin Mar 20 '17 at 18:46
11

The symlink solution for this stopped working for me in zsh today. I ended up creating an alias in my .zshrc file instead:

alias atom='sh /Applications/Atom.app/Contents/Resources/app/atom.sh'

scottmcallister
  • 163
  • 2
  • 10
  • same here, weird, I can't seem to understand why this happened. – Amin Shah Gilani Mar 13 '17 at 19:46
  • amingilani if you have installed the terminal for use with the `zsh` rather than the `bash` you need to put this alias on the file `.zshrc`: `vim ~/.zshrc` or `nano ~/.zshrc` for edit the file and then put on the final: `alias atom='sh /Applications/Atom.app/Contents/Resources/app/atom.sh'` save the file and then: `source ~/.zshrc` for load. – rld Dec 11 '17 at 18:40
  • this is great if you don't have administrator privileges on your machine +1 – Huw Davies Mar 28 '18 at 02:18
  • 1
    If you are using ZSH, uncomment the line `export PATH=$HOME/bin:/usr/local/bin:$PATH` in ~/.zshrc and restart the terminal – Sagar Ranglani Apr 08 '18 at 08:21
  • sh: /Applications/Atom.app/Contents/Resources/app/atom.sh: No such file or directory – Ashok R Oct 03 '19 at 03:18
  • @AshokR maybe the app is still in your downloads folder? You could still use this approach with something like `alias atom='sh ~/Downloads/Atom.app/Contents/Resources/app/atom.sh'` – scottmcallister Oct 11 '19 at 15:12
9

On macOS you can add it to your ~/.bash_profile

as

alias atom='open -a "Atom"'

and from terminal just call

atom filename.whatever

Alex Bartiş
  • 1,349
  • 13
  • 24
5

Open the application by name:

open -a 'Atom' FILENAME
Dejay Clayton
  • 3,210
  • 1
  • 24
  • 18
3

For Windows10 and new release of atom i solved the problem by adding in my ENV VARIABLE on the "PATH" row

%USERPROFILE%\AppData\Local\atom\bin
Laurent
  • 39
  • 3
2

In addition to @sbedulin (Greeting, lovely Windows users!)

The general path on Windows should be

%USERPROFILE%\AppData\Local\atom\bin

If you are using a bash emulator like babun. You'd better checkout the shell files, which only available in the real app folders

/c/User/<username>/AppData/Local/atom/app-<version>/resources/cli/apm.sh # or atom.sh
Community
  • 1
  • 1
Paris Qian Sen
  • 902
  • 9
  • 20
2

Iv'e noticed this recently with all new macs here at my office. Atom will be installed via an image for the developers but we found the Atom is never in the Application folder.

When doing a ls on the /usr/local/bin folder the path for atom will show something like "/private/var/folders/cs" . To resolve this, we just located atom.app and copied it into the application folder, then ran the system link commands provided by nwinkler which resoled the issue. Developers can now open atom from the command line with "atom" or open the current projects from their working director with "atom ."

Govna
  • 338
  • 4
  • 16
1

Another simple solution is to add /usr/local/bin to your PATH. I had the same issue, I installed shell commands (see shaheenery's response) the symlinks already existed and pointing to the correct destination (see thomax's response), however I would still get 'not found'. I'm using Korn Shell btw.

Here's what I did:

  1. Open your ~/.profile using your choice of editor (in my case $ emacs ~/.kshrc)
  2. Add this line: export PATH="/usr/local/bin:${PATH}"
  3. Save and exit
  4. Restart terminal or source ~/.profile
  5. Test $ atom -h
Jason Robinson
  • 768
  • 7
  • 11
1

Upgrading Atom appears to break command line functionality on the occasion. Looks like in my case it created two versions of the application instead of overwriting them. Occurs because the new file structure doesn't match file paths created by "Atom -> Install Shell Commands". In order fix the issue you'll need to do the following.

  1. Move "Atom X" from Documents into Applications (why it ended up in here, I have no idea)
  2. Rename "Atom X" to "Atom"
  3. Might need to restart your terminal and Atom

After that everything should work just like it did before. Hopefully this saves someone 30 minutes of poking around.

Ash Blue
  • 4,249
  • 4
  • 25
  • 33
  • Curious where you got Atom 3 from? Did you mean 1.0.3? According to their release page we're still in 1x.... https://atom.io/releases – sbuck Sep 02 '15 at 06:17
  • @Susan So am I, not too sure why I wrote that looking back at it. Adjusted to make more sense. – Ash Blue Sep 03 '15 at 23:13
1

Make sure to put (move) the atom into Application directory.enter image description here

0

With conemu on windows 10 I couldn't call atom from console even after I added %USERPROFILE%\AppData\Local\atom\bin to PATH in environment variables. I just added

alias atom="C:/Users/me/AppData/local/atom/app-1.12.7/atom"

to my .bashrc file.

Daniel Lizik
  • 2,890
  • 2
  • 16
  • 37
0

I had the same issue which I resolved by first moving Atom.app from downloads to Applications. Then under Atom's menu options, I selected "Install Shell Commands".

hal9000
  • 189
  • 1
  • 20
-1

I had problems due to atom being unable to write its logfile when starting from the commandline. This cured it.

sudo chmod 777 ~/.atom/nohup.out

andrew pate
  • 2,773
  • 26
  • 17
  • 2
    This looks like an issue with your permissions. You shouldn't have to use `sudo` in your own home folder. Is it possible that you started Atom using `sudo` before? That would explain why the logfile had the wrong permissions. Check the ownership of the file and then change it to be owned by your own user (using `chown`). – nwinkler Jun 28 '15 at 08:24
-1

add path(:/usr/local/bin/) in profile.

mac: $home/.bash_profile

export PATH=$GOPATH/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:$PATH

-1

I am on mingw bash, so I have created ~.profile file with following: alias atom='~/AppData/Local/atom/bin/atom'

Martin Kunc
  • 111
  • 7