what is the meaning of this Linux command? [duplicate] - bash

This question already has answers here:
Getting pids from ps -ef |grep keyword
(6 answers)
Closed 3 years ago.
I'm little bit new in sql command so please help me to clear this doubt
ps -ef|grep tomcat

This is not a SQL command,it's an unix/linux command check out forum answer below can clear your doubts.
https://askubuntu.com/questions/852206/what-does-ps-efgrep-processname-mean
In short :
look for lines containing processname in a detailed overview/snapshot of all current processes, and display those lines in linux command prompt environment

ps -ef says list all of the processes. (The -e option means every process, and the -f means use the "full" format in the listing.)
| says pipe the output of the previous command to the next command
grep tomcat say show (i.e. write to output) only those lines in the command's input that contain the string tomcat.
Combined, it means "show me the tomcat processes".
The "secret" to understanding a complicated Linux command is:
Understand the shell syntax; i.e. how |, <, >, $ and so on work.
Break the command line into its commands
Look up and read the manual entry for each command.

Related

What does | command do in terminal? [duplicate]

This question already has answers here:
What is a simple explanation for how pipes work in Bash?
(11 answers)
Closed last year.
I know for example: ls -all | grep Hello means to search all files containing Hello. What is the definitive definition of the | command? What exactly is going on here with |?
pipe; send whatever we get from the left side to the right side: (https://www.makeuseof.com/what-are-linux-metacharacters/) I would also take a look at the gnu bash manual: https://www.gnu.org/software/bash/manual/bash.html and check specifically the 3.2.3 Pipelines for more in depth information

How can I simply write all console output of a command to a file, in the terminal? [duplicate]

This question already has answers here:
print the output of strace command in a text file
(1 answer)
How to redirect and append both standard output and standard error to a file with Bash
(8 answers)
Closed 1 year ago.
I am trying to send all printed output of a strace command to a file. straces have a lot of console output since they print all the system calls of a command.
I have tried the most popular ways that I can find or think of, such as command > file.txt which does print output but then the output is not written to a file, same with command | tee file.txt Output is always printed but never written to a file. Is it because there is too much output or something? The first command definitely suceeds.
But my real question is what is the best way to do this and how can I get it done?
Many many thanks,
Milan

Why isn't 'which -a' listing the executable that will run? [duplicate]

This question already has answers here:
How can I check if a program exists from a Bash script?
(39 answers)
Closed 6 years ago.
I've read in some bash FAQ a while ago (that I don't remember), that which should be avoided and command -v preferred.
Why is that so? What are the advantages, disadvantages of either one?
Well...
command is likely built in to your shell, and with the -v option will tell you how your shell will invoke the command specified as its option.
which is an external binary, located at /usr/bin/which which steps through the $PATH environment variable and checks for the existence of a file.
A reason to select the former over the latter is that it avoids a dependency on something that is outside your shell.
The two commands do different things, and you should select the one that more closely matches your needs. For example, if command is built in to your shell, command -v command will indicate this with its output (through the non-existence of path), but which command will try to point to a file on your path, regardless of how command would be interpreted by your shell.

BASH echo showing some unusual behaviour [duplicate]

This question already has answers here:
Strange "echo" behavior in shell script
(3 answers)
Variables overwriting text problem with "echo" in Bash
(2 answers)
Closed 3 years ago.
This is the simple command that is giving me problems -
echo hafsda sfsdfdsfs $ymn $ymx $range
The output of this command is coming -
2.568 sfsdfdsfs 86.72
Where ymn = 86.72 ymx = 89.28 and range = 2.56. This only happens when I am using variables. The following command works fine -
echo hafsda sfsdfdsfs 1 2 $range
Also, the same command (the first one) works fine if I try running it directly in the terminal. This is only happening is a script. I also tried to use printf but encountered similar results.
I don't even understand what to google for to resolve this. I am unable to understand what is happening at all. So, what is happening here? Is this reproducible or is this just some error on my system, and if it is, what might be the problem?
Your script probably has DOS-style CRLF line endings. I suspect you actually have ymn="86.72\r" ymx="89.28\r" and range="2.56\r". You can test this in your script with
echo hafsda sfsdfdsfs $ymn $ymx $range | od -c
You can fix your script with dos2unix or sed -i 's/\r$// script.sh`.
Make sure you change the settings of your text editor do use unix line endings.

BASH script usage/help convention [duplicate]

This question already has answers here:
Is there a "standard" format for command line/shell help text?
(11 answers)
Closed 7 years ago.
What is the convention for showing the usage of a bash script ?
Below is the help output for my script
Usage: my_script [options] [PORT]
Options:
--help print help and exit
--version print version and exit
Am i right in thinking that [ ] means optional
How do I signify an optional argument and a mandatory argument ?
A couple of commandline tools that i use frequently is "find" and "grep". While find runs happy without any parameters (all parameters are optional) grep needs at least a pattern. In case grep is invoked with no paramters at all it prints usage information like follows
Aufruf: grep [OPTION]... MUSTER [DATEI]...
"grep --help" liefert weitere Informationen.
Where MUSTER is the german word for pattern.

Resources