Why did node version manager install to ~/.nvm instead of just ~/nvm and what is "sourcing" in Linux?

1

I was wondering about a simple event that occurred while I was installing node version manager on my 64bit Amazon Linux 2014.09 Web Server. When I executed this install script

curl https://raw.githubusercontent.com/creationix/nvm/v0.23.3/install.sh | bash

NVM installed onto my filesytem at ~/.nvm/

What is the significance of the ~/.nvm as opposed to ~/nvm ? Specifically, what does the ' . ' mean before nvm?

This is especially important because when I execute " ll " in the ~/ folder, I do not see any files. However, when I execute cd ~/.nvm , I am taken to the ~/.nvm folder.

Also, in order to get nvm working in the terminal, I had to "source" the nvm.sh file in this way

source ~/.nvm/nvm.sh

What did this source command accomplish?

Note: everything is working, this is just a curiosity I would like to understand better so that I feel more comfortable with server configurations etc.

Thanks a bunch!

deusofnull

Posted 2015-02-18T14:57:56.810

Reputation: 13

Answers

3

The character . at the beginning of the filename makes it hidden.
To see an hidden file from shell you can do ls -a (or ls -A).

Note the differences:

 .myfile.sh       # hidden file
 .   myfile.sh    # source the file myfile.sh

source (or .) are internal command of bash. You can have access to their definition with help.

With the command type you can understand if a command is a built-in shell or not.

E.g. the command type source /bin/ls will answer

source is a shell builtin
/bin/ls is /bin/ls

Then you can ask to the system information about the commands respectively with help or man.


From help source you can read

source: source filename [arguments]
Execute commands from a file in the current shell. Read and execute commands from FILENAME in the current shell. The entries in $PATH are used to find the directory containing FILENAME. If any ARGUMENTS are supplied, they become the positional parameters when FILENAME is executed.

From man ls

-a, --all
do not ignore entries starting with .

Hastur

Posted 2015-02-18T14:57:56.810

Reputation: 15 043

Is there a command for making a file un-hidden besides " cp -Rf ~/.file/ ~/file/ ? Will a file being hidden / un-hidden effect its functionality? – deusofnull – 2015-02-18T15:05:03.207

I didn't understand fully. If you do cp -Rf ~/.file/ ~/file/ you will copy the directory named .file and all hidden or not subdirectories in the directory named file if it exists, else in your home (~). Instead if file is a file you will receive as answer an error cp: impossible .... .file/ is not a directory – Hastur – 2015-02-18T15:17:20.353

Yeah, file was just a place holder. In this instance, the command would be cp -Rf ~/.nvm/ ~/nvm/ Would this change the functionality of nvm if you "source" it after this move? – deusofnull – 2015-02-18T15:35:35.490

About the action of source, give it a look to this. To source is like to execute all the script as you were writing that commands in the present shell. You question should be: what will it happens if I change the name in which is installed a script? ;) The answer is it depends from the script. It's possible you will have problem. I cannot know it from here, but for example each call with absolute path will search it in ~/.nvm/whateverelse... and not in you new directory ~/nvm/whateverelse.

– Hastur – 2015-02-18T15:47:24.473

Thanks for the link! So it is probably best to leave it in the hidden file... You rock – deusofnull – 2015-02-18T15:58:47.263

You're welcome. Continue to be curious, focused and you will rock even more in a blink of an eye! ;)

– Hastur – 2015-02-18T16:19:28.310

If you want the configuration files to be visible, add a link ln -s ~/.nvm ~/nvm. Note that there are two implications of hidden files: as well as not appearing in a default directory list, they also do not get expanded for *. To show all files in the current directory you need echo .* *, or echo .[^.]* * if you want to exclude . and ... – AFH – 2015-02-18T16:30:31.943

Do you really went to do that, @deusofnull? Because those hidden files and directories are usually configuration files for that the user can change. When a program starts (like nvm), it usual loads some basic settings that are part of the program (compiled into it). Then it reads a file (something like /etc/nvm) that the system admin (root) can use to make changes for all users on the system. Lastly the program reads configs for the user, that overrides all others (usually ~/.nvm). Notice that the namen is important. And it's nothing special with the ., it is just not printed by ls. – Anders – 2015-02-18T17:18:17.267

Ok, so the . just means ls doesn't print it, that's fine. I might do that sym link solution though, just for visibility if it wouldn't impact functionality. Is there a command for listing hidden files or do you just have to make note of it somewhere? – deusofnull – 2015-02-18T17:36:14.490

@deusofnull Yeah be curious but read carefully the answers too: ls -a, ls -A, echo .*, echo .[^.]* * ... ;-) and man ls for all the options... I forget tree -a if you have the command tree installed. – Hastur – 2015-02-18T17:59:12.993

Sweet! wow I didn't know all this about ll & ls! Thanks! – deusofnull – 2015-02-18T18:15:18.817

If your wondering why it's hidden, because you don't really go into the directory. You access it via commands. There is no point of having it visible, just clutters up your home directory. – Karl Morrison – 2015-03-26T13:49:56.830