Where shall I put my util shell scripts in linux [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I have read the Linux FHS, but still feel a little confuse. If I have some utility shell scripts, shall I put them in /usr/bin or /usr/local/bin or ~/bin?
The FHS says the most user commands goes to /usr/bin, but it also says that administrater should install unpackaged app or host specific stuff in /usr/local, does that means the /usr/local/bin is a better place for my own scripts? Maybe ~/bin is better? I want to know the best way / conventions to do this. Thanks

First of all, I wouldn't put anything unpackaged inside /usr/bin, there's already way too much mess in there without adding unpackaged stuff. Leave it to the package manager.
Now, if they are system-wide scripts, I would put them into /usr/local/bin, which is usually way less crowded, is accessible to everyone and editable only by root; if, instead, they are just for your user, you should put them into ~/bin.

Related

What is the quickest way to change your current location to your home directory? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I'm using Linux. I'm currently trying to set my current path location, as my home directory. Anyone have a clue as to what command I need to use?
The home directory has two different meanings, which usually are the same. The value of environment variable HOME (see environ(7)), and the field pw_dir given by password related API like getpwuid_r(3) on your current user id (obtained by getuid(2)).
At login, the HOME environment variable is set to the pw_dir and the effective and real user ids are changed.
To change your working directory to your HOME use chdir(2) on the result of getenv("HOME"). Notice that the working directory is not related to your PATH variable (which might mention .; but this could be a security issue), and each process (including your shell) has its own working directory (see also credentials(7), fork(2), execve(2), path_resolution(7), glob(7)).
To change your home directory (a very unusual requirement) you could edit -with root permissions- the /etc/passwd file carefully (see passwd(5)) then reboot your machine (or at least restart some login shell).
The bash cd builtin is doing that (changing the working directory of your shell process with the chdir system call). And when you use it without arguments you are changing your working directory to your home directory obtained by caching the result of getenv("HOME").
If performance matters that much inside some C program, you might cache (keep in some global variable, initialized once) the result of getenv("HOME") and use chdir on that.
If your question is simply about using your bash shell, just type:
cd
and that should (unless cd is badly aliased or redefined as some function) change the working directory of your shell to your home directory. It is done in a few milliseconds (so should be quick enough) at most (I can't easily think of a way to measure reliably how fast the cd shell builtin is; you could try time bash -c 'cd; pwd' or time bash -c 'cd; times' but that measures much more than just the cd and gives at most a few milliseconds on my desktop PC).
PS. the use of "quickest way" and "current path location" in your question is unclear and confusing. I strongly invite you to edit your question to improve its wording and motivate it and give more context.
I'm currently trying to set my current path location as my home directory. ? you can use EXPORT PATH.
for e.g Run below command in command prompt
export PATH=$PATH:$HOME/user
This changes happens only in current session, to make it permanent add it to .bashrc file.

How to block Particular Commands in Linux for Specific user? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Suppose i create a new user TEST in ubuntu and i need to block all commands except cp,ssh,exit.Please help me.i am new to linux.
Alternatively, consider using some restricted shell like rbash which you might set up as the user's login & ssh shell (use chsh and/or configure his/her's ~/.ssh/config); of course set up the PATH appropriately, it might contain a single ~/bin/ directory containing symlinks to /bin/cp, /usr/bin/ssh, etc. You might want to make ~/bin/ not owned and not writable by the user.
Be careful: if your user is more experimented than you are, you might leave some holes that he/she would be able to exploit. Make it also a social/contractual issue, by at least explicitly forbidding (in words) things.
You might also want to learn more about chroot and/or setuid; see also the references in this answer.
Notice that if your user gets ssh, he is likely to get scp and be able to hack his account (e.g. by adding executable files into his ~/bin/ ....)
I think you need to create a new group in which you set all the commands you want to use and add your TEST user to this group.

How commands are processed in LINUX [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am new to LINUX. This question sounds simple and stupid, but I suppose this has a lot of meaning behind it. "HOW COMMANDS ARE PROCESSED IN LINUX?". Which means suppose if I give ls command,what makes it to display list of all files inside the directory?. I have been searching for the answer, and I could not find any clear explanation for the same. Please help me to solve the same.
I'm new too. But I can answer this in a top level.(not too many details).
Everything in Linux is file, which means that the ls is also a file. You can type which ls
and you can see the file's location.
So, a command is a file, when you type and Enter, the system will search for the file in your PATH and execute it. When the file is executed, it will talk with the kernel and tell the kernel what resources it wants to use, and then the kernel will talk with the real hardware and let the computer do the work.
Some commands are shell keywords or shell builtins, so the shell (the program that accepts your commands) recognizes and processes them directly. Many other commands are executable programs found in the path; so, for example, if you enter ls, an executable called ls is executed (usually found in /bin, many commands cann be found in /usr/bin/). A command could also be an alias for another command.
You can use type command to find out what kind a command is, e.g.
type ls.

In a Unixy filesystem, where is the conventional place to put software you're working on? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
This is an incredibly dumb question, but I don't know the answer. Apologies in advance.
I want to download a repo of someone else's code from GitHub to work on it. In a Unix-y filesystem, where is the most conventional place to put it?
I've been reading about standard directory structure on Wikipedia and it looks like below opt might be the most appropriate place. Is that correct?
I'm using MacOS, so the alternative would be for me to create a custom folder under /Users/me, but I wondered if there was a conventional place for working on code within the standard Unix directories.
It depends on your usage plans. If this is code you want to hack on, typically your home directory is the right place, since this is private to your unix user. I personally make a 'dev' subdirectory and put code in there (mine or other people's, via github).
If you're looking to install this software system-wide, the answer varies slightly by the system. /opt is a reasonable choice in most cases, as is /usr/local.

Where should I place a download tarball? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I downloaded ChromePlus tarball and extracted it to my home directory. The extracted folder contains an executable that I can double-click to launch ChromePlus. So I assume I do not need to any extra things to install it.
I'm new to Linux. Where should I place ChromePlus directory? It's currently sitting on my home directory and it does not look neat. After googling, I thought about /bin/, /usr/bin, /usr/lib. Where is the best place?
I usually do so. I put the extracted directory to /usr/local and make a link to the binary in /usr/local/bin, so it looks something like:
/usr/local/bin/theapp -> /usr/local/Theapp/bin/theapp
If I care about upgrading Theapp and the extracted directory contains version then I also symlink "Theapp" to point to current version of it, e. g.:
/usr/local/Theapp -> /usr/local/Theapp-1.0.0
Since /usr/local may not be writable on some systems that you have access to, one's home directory is often the only place. For things like compiling the Linux kernel source code, using /usr/src, a path outside a home dir, is even discouraged.

Categories

Resources