
이 명령의 출력을 리디렉션하고 싶습니다.
ps -eo pid,comm,cmd,start,etime | grep -i qtcreator > file.txt
시도했을 때 명령도 출력했습니다.grep -i example
2018 qtcreator qtcreator 08:11:50 01:05:00 <br>
5513 grep grep -i qtcreator 09:16:50 00:00
이 문제를 어떻게 해결할 수 있나요?
답변1
다음과 같이 명령을 편집하면 문제를 해결할 수 있습니다.
ps -eo pid,comm,cmd,start,etime | grep -i qtcreator | grep -v grep > file.txt
이렇게 하면 첫 번째 grep 결과에서 ward grep을 제외할 수 있습니다.
답변2
더 깨끗한 방법은 다음을 pgrep
사용하는 것입니다 ps
.
ps -p $(pgrep <program-name>)
[iahmad@localhost]$ ps -p $(pgrep sendmail)
PID TTY STAT TIME COMMAND
32373 ? Ss 0:59 sendmail: accepting connections
32383 ? Ss 0:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue