Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I want find highest cpu utilisation process.I am using
ps -aux|awk -F " " '{print $2" ,"$3}'|sort -r | head -5
Please help me if this is right or wrong command.I am getting 'Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ'
ps aux --sort %cpu | tail -n 1
user 5627 7.6 16.0 1928396 1331680 ? Sl Mar12 120:58 /opt/firefox/firefox
-n 1 gives the highest, adjust number to give highest x processes. Tail because default (+) for --sort is lowest to highest.
To get just the top cpu itself though that's not particularly useful:
ps aux --sort %cpu | tail -n 1 |awk '{print $3}'
7.6
To get it with the headers use highest to lowest (-) sort:
ps aux --sort -%cpu | head -n 2
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
user 5627 7.6 16.0 1928396 1331680 ? Sl Mar12 120:58 /opt/firefox/firefox
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Below I shared my console. I want to cut some string from output of some commands.
But there are 17 extra chars which I have no idea where comes from.
Can someone pls explain to me?
$ ls -al | grep total | sed 's/[[:blank:]].*$//' | wc -m
23
$ ns="total"
$ echo $ns | sed 's/[[:blank:]].*$//' | wc -c
6
But there are 17 extra chars which I have no idea where comes from.
Those are ANSI escape codes that grep uses for coloring matching substrings. You probably have an alias (run alias | grep grep to examine) like
alias grep='grep --color=always'
somewhere that causes grep to color matches even if output is not a tty, or something similar.
Try
ls -al | grep --color=never total | sed 's/[[:blank:]].*$//' | wc -m
and you'll get six.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
How do I kill all processes returned from the following?
lsof -i
I have tried the following to no avail:
lsof -i | awk '{print $2}' | kill
kill takes PID's as its arguments whereas when you pipe it, it goes to the stdin of kill.
Pass them as arguments:
kill $(lsof -i | awk '{print $2}')
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to get some informations from this string (df command)
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 19G 3.8G 14G 22% /
I need to get:
The available space value
And the used space value
Thanks guys!
Use awk:
df / | awk 'FNR>1 {print $3, $4}'
To print the columns of the second line of the command, you can use awk or similar:
$ df -h / | awk 'FNR==2 {print $1, "used: " $3, "avail: " $4}'
For scripting purposes you could read the command output into an array and get your values there:
#!/bin/bash
line=( $(df -h / | tail +2) )
printf "%s\n" "${line[0]} used: ${line[2]} avail: ${line[3]}"
This is another solution, without awk.
df / --output=used,avail | tail -n +2
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
What command can I use to find a process that's using a lot of CPU? Can I do this without installing something new?
Or using a few other utils you could do:
ps aux | sort -rk 3,3 | head -n 5
Change the value of head to get the number of processes you want to see.
Try doing this :
top -b -n1 -c
And if you want the process that takes the most %CPU times :
top -b -n1 -c | awk '/PID *USER/{print;getline;print}'
or
top -b -n1 -c | grep -A 2 '^$'
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
When I run
echo "obase=2;3" | bc | grep -v \n\s | wc -m
bash returns 3. But when I run
echo "obase=2;3" | bc
bash returns 11.
Why is wc -m one digit high on its count?
The extra character is the trailing newline.
wc -m receives and counts the following three characters: 1 1 \n.
$ echo "obase=2;3" | bc | grep -v \n\s | od -c
0000000 1 1 \n
0000003
If you get rid of the newline, the count will be as you're expecting:
$ echo "obase=2;3" | bc | grep -v \n\s | tr -d '\n' | wc -m
2