Morgan Stanley Interview Question: A few questions on basic comm... |

Interview Question

Software Engineer Interview Montreal, QC

A few questions on basic command-line syntax in Unix

  shells: 1. How would you log output and error messages from a command to a file? 2. How would you run the same command on every file in a directory? 3. How would you find the PID of a named process (say if you wanted to kill it)?

Interview Answer

5 Answers


1. command >file 2>&1
2. cd dir; for i in *; do command; done
3. ps | grep processname or ps -C processname

Interview Candidate on Feb. 28, 2012

#3 I disagree, more like ps aux |awk '$0 ~ /ProcessName/ && $0 !~ /awk/ {print $2}'

If you want the PID

Gregg Leventhal on Mar. 3, 2012

#3 To find the PID:

pgrep -x

Kenroy Harrison on Aug. 24, 2012

#3 - to find the PID
Or simply use: pidof

Santanu on Apr. 30, 2013

Opps!! there is typo; it should be: pidof

Santanu on Apr. 30, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.