I'm redirecting results for something into a file and I also need to find the process name and ID number and redirect it to the file as well. I'm guessing the process name is the command in which I'm directing the results to. As in if the command is pgrep sshd and I redirect the results to the file, pgrep sshd would be the process name. I'm just curious though how exactly I find the process ID number and what would be the simplest way to redirect it to a file if there is a command to find it.
Here is the original objective I was given, I'm sorry if I seem really new at this, I am a student.
Man pages usually have a helpful section near the end called "SEE ALSO" that you can use to find a list of commands and topics related to the command that the current man page is about. Use this feature to locate a command related to "ps" that will search for processes based on some criteria. Use this command to locate all processes called sshd, directing the output to a file named
processes.txtin~/sysadmin1, making sure that the command also prints out the process name next to the process ID number. You will have to specify a flag with the command that you find in the man page for the command in order to do this. When you have finished add the full command used to the top of theprocesses.txtfile.
sshdand it's pid is22143and I wanted the output into a file as22143 /usr/sbin/sshdI would run something likeps aux|grep [s]shd | awk '{print $2, $(NF-1)}' > processes.txtpsman page for a similar command that "will search processes based on some criteria".man pshas detailed information. I'm just providing some ideas. What I could get from the manual. This would be another exampleps xgc | awk '/[s]shd/{$2=$3=$4=""; print }' > processes.txtpscommand.