tags:

views:

85

answers:

4

Hello people, I'm having a problem with regex in using the command sh cute, the problem is that I want to show all processes that start with g and just show the command, but do not know, help me please?

To do this I use the command:

ps aux | grep g 

but this show all process who contains the letter g and i need who start with g and cut the command to get this, for example i get a output of ps

root      1012  0.0  0.0   6128   644 tty4     Ss+  16:10   0:00 /sbin/getty -8 38400 tty4

1000 4571 0.0 0.0 12724 868 pts/4 S+ 19:21 0:00 grep --color=auto g

And I need get only /sbin/getty because is in path and the command grep. In definite get all files start with g and cut and cut above so that it is the command and attributes PD: I need use to get all with the commands grep and cut, and i can't don't use the pgrep.

Thanks in advance

A: 

You don't need cut:

ps -ao command | grep g
Cfreak
when i put this /sbin/getty dont show
Alejandro Espinosa
What does show? It worked on my system.
Cfreak
A: 

what about this:

ps -o "comm" -A | grep -E "^g"
hellvinz
A: 

You can't split with cut on a regex, a group of spaces in this case. You can either cut from a certain bytes, or cut by a single character delimiter. So you can do

ps aux | cut -b66- | grep g
Adam Schmideg
A: 

Maybe this:

ps -eo command | grep -E '^(|\S*/)g'
hluk