Print all PID folders from /proc line-by-line with this format (( PID: command-line ))
How do you extract all numeric folders from PIDs variable, which is defined as:
Code:
PIDs="$(ls -v /proc/)" # -v for numeric sort Code:
numberOfPIDs="$(ls /proc/ | wc -l)" |
Code:
ls -dv [1-9]* |
Excellent.
How can I use your snippet outside /proc folder? Why this doesn't work: Code:
ls -dv [1-9]* /proc/ |
Code:
ls -dv /proc/[1-9]* |
This for loop is much better, but it still gives plenty of errors:
Code:
PIDlist="$(ls -dv /proc/[1-9]* | cut -d '/' -f3)" # I need only PIDs |
Keep it simple. You might loop over the /proc/PID directories and use parameter substitution or the basename command to retrieve PID. Example:
Code:
for i in /proc/[1-9]* |
What do hash-hash-star-slash, that is ${i##*/}, in printf do? :)
EDIT: Oh, I'm sorry, now I see it in comment. Forward to man basename! :study: Thank you again. |
Actually it is substring removal. Look at the advanced bash scripting guide, here.
Code:
${string##substring} |
All times are GMT -5. The time now is 08:36 AM. |