Why can't I see paths that exist in OSX? - node.js

I am a windows developer switching over to OSX. I am very confused though. I am learning node.js and the documentation tells me to add a reference to nodemon at the path...
/usr/local/bin/nodemon
However when I am at the terminal and I type 'ls' I get the following output...
And that doesn't have a /usr/ folder ... And what is even more confusing is that if I do...
ls -a
Then I can see all my hidden folder with a folder in called .npm which seems to have all my modules. In windows this is easy it just installs all npm modules into %AppData%/npm or something but I just don't get it on OSX can somebody enlighten me please?

ls lists the directories and files in your current working directory.
You can find your current working directory with pwd (short for 'print working directory')
You can change your current working directory with the cd (change directory) command. In your case, you could run
cd /usr/local
ls
and it would show you the bin directory. Alternatively, you could directly run
ls /usr/local
As a special extra note, the Terminal Prompt itself actually displays the current working directory (by default). In your case, it shows ~, which is shorthand for the user profile directory, which the Terminal opens to automatically. It is generally /Users/<username>.

Related

Where to put application so I can use them no matter working directory?

I installed ngrok and put it in the /bin folder. But I can only use the command ./ngrok when I'm in the /bin directory. I'm pretty new to using Linux but I'm quite shure that /bin apps/command can be used everywhere. Anybody know where to put applications so I can use them no matter what's my current working directory.
If /bin is in the $PATH, you can call it with ngrok, without specifying the current directory ./.

Activating Venv in Bash without changing child directory

Edit: Thanks to everyone commenting below. The purpose of this question was to figure out a way to execute the venv given that we are in a child directory and the venv folder is located in parent directory.
example: there are three folders inside parent directory:
/home/iamuser/ ls
.venv random_files pictures
Currently we are inside folder "random_files"(/home/iamuser/random_files) . We need to find out a way to start venv which is inside parent directory.
First way is to use cd .. to get to the parent directory**(/home/iamuser/)** , then type Source ./venv/bin/activate
Second way is to use the following command directly from "random_files" folder.
Source ../venv/bin/activate
This will start venv in "random_files" folder (child directory) without forcing us to change directories.
The issue is solved. I hope my answer helps someone.
*****************************OLD Thread *******************************
I have been trying how can I activate virtual environment without changing path.
While writing this question, I am at: /home/user
If I do cd .. I will go back one directory to the home, if I do cd .. again I will go back to the top of the tree.
At that place, I have my venv located.
To activate venv, I use cd.. twice to go to that position and then I type source venv/bin/activate. I am looking for a solution where I donot have to use cd.. twice
Can I get a script that could activate venv without forcing me to change directory.
You can use the absolute path
source /venv/bin/activate

Weird recursive directory structure

Somehow, my system (Ubuntu WSL layer on Windows; so treat as exactly Ubuntu) went a bit crazy. For a directory (a git repo if it matters) /path/to/foo, running ls shows the git files ORIG_HEAD, index, and index.lock in there.
I tried to debug this by going cd .git, but an ls there showed me my same list of files as the parent!
I went as far as
/path/to/foo/.git/.git/.git
before stopping checking the recursion.
A possibly related issue that managed to show up is that the .htaccess file there is read as a file by Emacs on Windows, a file by vi on Linux, but a directory by emacs and a directory by bash.
That means that my computer really thinks
~/public_html/.git/.htaccess/.htaccess/.git/.htaccess/.git/.git
is identical to
~/public_html
So, needless to say, Apache also craps out and says that it's an invalid htaccess file .... though on an other machine (see: git repo) it runs just fine.
Help?
Tried nuking the directory via rm -rf and git clone-ing back, but the Apache problem persisted.
I removed the symlink to the directory via unlink:
~$ unlink public_html
then re-mounted it, making sure that there wasn't a trailing space
~$ ln -s /mnt/c/Users/USER/pathto/repo /home/USER/public_html

Can't execute from /usr/local/bin/ symlink

I've recently had to compile a program (Riak) from source since they don't have a repo available for Ubuntu 16.04 yet.
I've compiled the program and copied it to /opt/riak where it works fine.
Since this program requires sudo privileges, I've decided to symlink /opt/riak/bin/riak to /usr/local/bin/riak instead of adding the variable to the path via a profile.d file (because in order to work with sudo I'd have to remove env_reset from /etc/sudoers which I rather not do).
The error I get is the following:
/usr/local/bin/riak: 8: .: Can't open /usr/local/bin/../lib/env.sh
Shouldn't the symlink execute the file from the original's working directory? Is there a way to make it work?
The error message is almost self explanatory. Apparently the riak executable is trying to find a file called env.sh using a path relative to its own, namely ../lib/env.sh. Originally, this would resolve to the following path: /opt/riak/bin/../lib/env.sh, which is the same as /opt/riak/lib/env.sh. But now is trying to find the file at /usr/local/bin/../lib/env.sh which is the same as /usr/local/lib/env.sh and obviously the file is not there.
You have the following options (in order of preference):
Leave the program in /opt and invoke it from there
Leave the program in /opt and create a small wrapper shell script in /usr/local/bin that calls the original executable (see at the end of this post).
Recompile the program passing the right parameters to its configure script (e.g. --prefix=/usr/local) so that it works from /usr/local.
I would recommend against option 3; I prefer to let the /usr directory be managed by the distos package manager. If I have to compile something myself, I prefer to put it in a dedicated directory bellow /opt. This way, if I want to remove it later on, I can just delete that directory.
Example wrapper script for option 2:
#!/bin/bash
exec /opt/riak/bin/riak "$#"

How to create a cygwin executable

I was trying to follow the instructions here to get drush installed on cygwin:
https://www.drupal.org/node/1432756#comment-11184267
However, running "drush" from my drupal project's folder did nothing (it didn't tell me -bash: this_command_I_made_up: command not found as it does for a command that doesn't exist).
Eventually I tried to run the symlink command like this:
ln -s /usr/local/src/drush/drush.bat /usr/bin/drush.bat
instead of this:
ln -s /usr/local/src/drush/drush.bat /usr/bin/drush
In other words, I added the .bat suffix to the filename path (drush.bat) instead of leaving it as plain old drush. Now I get results as I expect when running drush commands from my drupal project folders, but I have to type in drush.bat instead of drush when running drush commands.
I was just wondering if anyone could shed some light on the situation as to why the plain old drush symlink without the .bat suffix doesn't work. Thanks!
You may need to make the src/drush/drush.bat executable. If the symlink you make has a .bat extension (or .exe, etc.), it will automatically be executable in cygwin.
For files without extensions, the file must be marked executable.
For symlinks without extensions, the source (src/drush/drush.bat) must be marked executable.
To mark a file executable, use the command chmod +x src/drush/drush.bat.

Resources