Get all processes whose name contain Gilles Quénot get a simple solution--simple solution
{ head -2; sort -n; } {} get input redirect by
firefox
and exclude grep
process,it is no use to show all processes here,omit many lines.
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
The output does not contain header info in ps
's command ,in order to get the header,add head -n1
after the 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
Other bash command:
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
Why can't get the below output when to execute 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
Why grep in "ps aux |(head -n 1 ;grep [f]irefox)" can get lines to match?
As expert user10489
point out:
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.
Another post can explore it in depth:
cat > raw.txt <,if head -2;
run as user10489
say:head takes all of the output, prints the first line, and then quits throwing away all the rest of what it read.
,why sort -n
have lines to sort with?
The result would be
ID DESCRIPTION
----- --------------
No lines sorted!!!
Asked by showkey
(499 rep)
Feb 15, 2025, 04:30 AM
Last activity: Feb 16, 2025, 09:12 AM
Last activity: Feb 16, 2025, 09:12 AM