Obtenha todos os processos cujos nomes contenham firefox
e excluam grep
o processo. Não adianta mostrar todos os processos aqui, omita muitas linhas.
ps aux | grep [f]irefox
debian 7069 1.0 4.4 3134148 359168 ? Sl 11:58 0:12 /usr/lib/firefox-esr/firefox-esr
debian 7128 0.0 0.4 223884 36824 ? Sl 11:58 0:00 /usr/lib/firefox-esr/firefox-esr -contentproc -parentBuildID 20241118130310 -prefsLen 28341 -prefMapSize 249085 -appDir /usr/lib/firefox-esr/browser {0c853969-95e1-4db0-9e95-eeaee3d4f814} 7069 true socket
A saída não contém informações de cabeçalho no ps
comando 's, para obter o cabeçalho, adicione head -n1
após o pipe.
ps aux |(head -n 1 ;grep [f]irefox)
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
debian 7069 0.9 4.4 3134148 361740 ? Sl 11:58 0:13 /usr/lib/firefox-esr/firefox-esr
debian 7128 0.0 0.4 223884 36824 ? Sl 11:58 0:00 /usr/lib/firefox-esr/firefox-esr -contentproc -parentBuildID 20241118130310 -prefsLen 28341 -prefMapSize 249085 -appDir /usr/lib/firefox-esr/browser {0c853969-95e1-4db0-9e95-eeaee3d4f814} 7069 true socket
Outro comando bash:
df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 3977796 0 3977796 0% /dev
tmpfs 804900 1356 803544 1% /run
/dev/sdb1 460349516 143209832 293681076 33% /
tmpfs 4024488 100444 3924044 3% /dev/shm
tmpfs 5120 16 5104 1% /run/lock
df | grep shm
tmpfs 4024488 101536 3922952 3% /dev/shm
df |(head -n1; grep shm)
Filesystem 1K-blocks Used Available Use% Mounted on
Por que não consigo obter a saída abaixo ao executar df |(head -n1; grep shm)
?
df |(head -n1; grep shm)
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 4024488 101536 3922952 3% /dev/shm
Por que grep em "ps aux |(head -n 1 ;grep [f]irefox)" pode obter linhas correspondentes?
Como user10489
apontam os especialistas:
The command df |(head -n1; grep shm) does this:
df generates some output
head takes all of the output, prints the first line, and then quits throwing away all the rest of what it read.
There is no output left for grep to take as input.
Outro post pode explorá-lo em profundidade:
cat > raw.txt <<EOF
ID DESCRIPTION
----- --------------
2 item2
4 item4
1 item1
3 item3
EOF
Quero obter as linhas abaixo classificadas com cabeçalho:
ID DESCRIPTION
----- --------------
1 item1
2 item2
3 item3
4 item4
Gilles Quénot
obtenha uma solução simples - solução simples
{ head -2; sort -n; } <raw.txt
Quando o comando em {}
obter redirecionamento de entrada por <raw.txt
, se head -2;
executado como user10489
digamos: head takes all of the output, prints the first line, and then quits throwing away all the rest of what it read.
, por que sort -n
ter linhas para classificar?
O resultado seria
ID DESCRIPTION
----- --------------
Nenhuma linha classificada!!!