简体   繁体   中英

How can I exit the 'loop' of 'top | grep user'?

I want to use top | grep user top | grep user to know how many processes are running.

However, after I run top | grep user > temp_file top | grep user > temp_file , the command just keeps running.

How can I safely stop it with information being written to the temp_file ?

You can use the -n 1 option to top to make it only do one iteration.

Probably the better tool to use would be ps , as in ps aux | grep user ps aux | grep user .

如果计数是您感兴趣的全部:

pgrep -cu username

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM