How commands are processed in LINUX [closed] - linux

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.

Related

Script program inputs in bash ubuntu linux [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
I'm in a course for C++ programming.
Our professor created a linux validation script against which our program output must match exactly.
It's running out of his own program and generates an output.txt file, then compares it against his output file, if it doesn't match it rejects the script.
The problem is, this program excepts probably 150-200 lines of input and if anything goes in wrong you have to start all over again. If you even enter an incorrect char, it must be restarted as the backspace registers as a character of its own.
How might I generate a bash script that would feed all of the input into the program automatically?
NOTE: We have to use his program as in: ~professor.name/submit asigname
You can create a text file:
answers.txt
answer1
answer2
...
answerN
and use that as stdin for the program:
./your_program < answers.txt
How might I generate a bash script that would feed all of the input into the program automatically?
Without any example code or input/output, it is hard to gauge what precisely is that you need.
Otherwise, for a generic tool to automate interactive console programs, I would suggest to take a look at the Expect.

What exactly is executable code? [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 7 years ago.
Improve this question
I know about executable code, but I don't know what it exactly is.(for the system)
(I'm thinking about .sh or something else)
I tried to find something out with www.google.com but there was no result.
Can anyone explain it to me?
This is kind of a loose term but I would interpret this as a program that can be executed.
For example, if we have a Java file it is not directly executable...it's just a bunch text to the end user. You can't run the file directly like:
./foo.java # bad
Conversely, if you had a sh script that could be interpreted by your shell (and it has the proper permissions set, such as the executable bit) then it is executable. For example you could do:
./foo.sh # good
Another example would be code that has been compiled. If that foo.java file had been compiled into byte code then (assuming it had a main function) it could be executed directly (not the .java file, but the output of the build).
java foo # good
So, I think in this context, executable code means a file with code in it that can be executed directly by an end user.
To put it simply, "executable code" is any sequence of program instructions which is intended to be executed in some environment without prior translation. For example, a "binary executable" contains instructions which can be carried out by an appropriate microprocessor. An "executable shell script" contains instructions which are meant to be executed as-is by a shell program; from the shell's perspective, the script contains executable code, but from the processor's perspective it doesn't.

Correcting misspelled bash commands [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 7 years ago.
Improve this question
I'm looking for a way to correct bash commands if they have been misspelled.
Let's say you have installed a program called "FooBar" but you type "foobar" (or foo bar or FOOBAR or foebar) in your shell. Is there any way to check if something similar to what you are looking for exists in your PATH?
I'm thinking about writing a bash script that normalizes user input and uses the Levenshtein distance algorithm to check what they have typed against anything in PATH. But maybe there's already something is written out there or a better way to accomplish this task.
Any suggestions?
If you problem is case-sensitivity only, then you can switch this off in the readline configuration by the following:
echo "set completion-ignore-case On" >> ~/.inputrc
However, if you are seeking for some clever mechanism to execute similar commands (by using fuzzy logic for example) I'll not recommend to use such tool in a command-line since it could be very dangerous.
Imagine what could happen for example in commands like rmv? is it rm or mv? .. only the user can answer this question.
Note: This may be useful if you are running a Cygwin env where case-sensitivity is not a problem. In Linux commands are case sensitive. So switching this functionality off is not a good idea.

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.

Order of files to be executed in linux and how to change it [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
What is the order in which executables are searched by linux for executing when a command is executed. I have following:
/bin/play
/home/prabhat/playframework/play
both the above files are in path.
When I execute it from my home directory as in below
prabhat#localhost~/home/prabhat/$ play
/bin/play gets executed.
What is the order in which linux searches for files to be executed. Is there a way to change it?
The order is defined by the entry order in your PATH variable.
Note that your shell may cache this info and when you change the PATH you may need to refresh this cache. In bash this is done by the hash command. See here for more information.
hash command maintains a hash table, which has the used command’s path
names. When you execute a command, it searches for a command in the
variable $PATH. But if the command is available in the hash table, it
picks up from there and executes it
you need to move /home/prabhat/playframework/ before /bin in your path. you should be able to do this in your .bashrc or .bash_profile
something along the lines of:
export PATH=/home/prabhat/playframework/play:$PATH
hope this helps

Resources