How to make directory at Linux root directory from terminal when in sub-directory? - linux

Background: OS is Debian GNU/Linux.
I am trying to make a directory at root, when I am in a sub-directory. In other words, let's say I am at the directory /a/b/c, and I want to make a directory at the root level, called d. How do I go about doing that?
In case you can't tell, I also don't know all the right wording/terms.
UPDATE: I did not understand difference between home directory and root directory. I learned about pwd command, and that solved the problem. What I actually wanted was to make a directory within the home directory.

Assuming that you have the required permissions, you could do mkdir /d.

It should be like sudo mkdir /name_of_directory

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 ./.

NodeJs/NestJs which directory to install on Unix

Hi I have nodejs/nestjs microservice running in forever. I have installed in /home directory. I Have been reading around and home is not the correct place for this to be installed.
What is the correct directory to install it into? I is /srv or /usr/local or something else completely?
I think the best directory for things like that is /opt
You can read more about /opt and whole Filesystem Hierarchy here:
https://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/opt.html
https://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/index.html

Why can't I see paths that exist in OSX?

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>.

working on lamp server in ubuntu

i m working on ubuntu and just installed lamp.As i m new to linux i m not sure how to create a directory or file under /var/www of lamp server to start working on my website project
Under *nix you can create a directory using mkdir newdirname and you can create a new and empty file, using touch newfilename. Those are commands you need to execute from a shell/terminal. In order to get to /var/www, you will need to cd /var/www.
If you are new to Linux I suggest reading any guide on basic like this or this.
Chances are you do not have sufficient privileges as your normal user to add files or create directories. You can either change the ownership of the /var/www directory (and everything within) or you can sudo each one you want to add.
From the prompt: chown [your_user_name].users -R /var/www
Then you can mkdir [directory name] to make a directory or touch [filename] to create a file.
If you do not change the permissions of the /var/www you may need to put sudo in front of each of the above commands (will be prompted for password)

Bash scripting and user home from root account (Linux)

I'm writing an install script in bash for an application on Linux.
This script copies some files into /usr/bin and /usr/share, so it needs to be executed by a root user, furthermore it makes an hidden directory in the $HOME dir for configuration files.
Here is the problem: if a normal user wants to install the program, he needs to be root. But if he is root, the $HOME directory will be /root/ instead of /home/username.
...and, further, if UserA installs the software, but UserB runs it, UserB won't have the hidden directory under /home/UserB. Also, the hidden directory under /home/UserA will be owned by root, not userA.
So, you need to have the application create the hidden directory, not the installer.
Another possible option is not to install in the system directories; one possible alternative location is /usr/local. However, even that can require root privileges. Think about whether it can be installed in other places, and how it could locate its materials.
However, requiring root privileges to install is not the end of the world - a nuisance for some, but not completely out of order. But requiring everyone who uses to have root privileges is way out of order - and if everyone who uses it needs to run the installer, that is bad.
Final point (for now): if you use sudo, it does not change the value of $HOME, even as you acquire root privileges. However, requiring everyone who uses your application to have sudo privileges is not a good thing either.
Must you use $HOME? Maybe you could prompt for the username and install to ~$username instead?

Resources