LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-22-2012, 06:36 PM   #1
lovesuicide
LQ Newbie
 
Registered: Dec 2012
Posts: 7

Rep: Reputation: Disabled
ps aux command to list only files in brackets


Hi everybody,

I am looking to do the following: give a command line starting with ps aux that will print only entries with square brackets around the command field. I need to use a pipe after ps aux and keep in mind that the COMMAND field comes last in the output.

I believe I need to create a way to list files that are in brackets only. I've been able to create a command to exlclude files in brackets by typing the following:

grep -v ]

But I need to know how to create the opposite effect, and list only the files in brackets. Can anybody help?

Sorry for being such a beginner, but this problem has got me stumped.


Thanks!
 
Old 12-22-2012, 06:51 PM   #2
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
try this, you might have to change the # value in the awk command, but this should get you started:

Code:
ps -aux | grep -v grep | awk '{print $11}' | grep -e ]
ps -aux = what you expect

grep -v grep = the -v excludes what is after the -v, in this case it will not display itself in the search

awk '{print $11}' = this will print ONLY the 11th field of the ps -aux

grep -e ] = this will look for ONLY matching the ] in the search.

hope that helps.
 
Old 12-22-2012, 07:37 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
Code:
ps aux|awk '/\]/{print $11}'

Last edited by unSpawn; 12-22-2012 at 07:52 PM. Reason: //Shorter
 
1 members found this post helpful.
Old 12-22-2012, 08:41 PM   #4
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
now that is a much cleaner way of handling the search unSpawn. im learning. that is more to what i was wanting to do, but could not figure it out fast enough.
 
Old 12-22-2012, 11:18 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
Then you might like David the H.'s advice and pointers here.
 
1 members found this post helpful.
Old 01-08-2013, 06:58 PM   #6
lovesuicide
LQ Newbie
 
Registered: Dec 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
thank you everybody! This accomplished exactly what I was looking to do.
 
Old 07-03-2013, 03:46 PM   #7
Alucarx85
LQ Newbie
 
Registered: Jul 2013
Posts: 6

Rep: Reputation: Disabled
I was looking for that

Last edited by Alucarx85; 07-03-2013 at 04:37 PM.
 
Old 07-24-2013, 03:22 PM   #8
Alucarx85
LQ Newbie
 
Registered: Jul 2013
Posts: 6

Rep: Reputation: Disabled
the right answer to this is ps aux|grep -e ]$
 
Old 07-24-2013, 03:41 PM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by Alucarx85 View Post
the right answer to this is ps aux|grep -e ]$
No it is not....

The OP wants the commands only, not all the other output:
Code:
root         1  0.0  0.0   8356   816 ?        Ss   07:50   0:01 init [2]

# vs

init [2]
Both answers given by lleb and unSpawn are not fully correct either; They only print field 11 and there can be more (see the above example).

Have a look at this:
Code:
ps ax -o args | grep -e "\]"
 
Old 07-24-2013, 03:57 PM   #10
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,836

Rep: Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360
Quote:
Originally Posted by druuna View Post
Have a look at this:
Code:
ps ax -o args | grep -e "\]"
I have to chime in, because grepping through the process list -- i do this often.

How about:

Code:
ps ax -o args | grep -e "\]" | grep -v grep
 
Old 07-24-2013, 04:26 PM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
Quote:
Originally Posted by szboardstretcher View Post
Code:
ps ax -o args | grep -e "\]" | grep -v grep
If you find yourself using 'ps|grep something|grep -v grep' a lot then know there's pgrep.


Quote:
Originally Posted by druuna View Post
Both answers given by lleb and unSpawn are not fully correct either; They only print field 11 and there can be more (see the above example).
You're right.

*BTW if the objective would have been to find kernel threads then they're children of kthread (2.6) or kthreadd (3.x) which could be expressed as 'pgrep kthread; pgrep -P $(pgrep kthread)'. For user land processes pgrep works as well: 'pgrep -f "\[";'.
 
Old 09-20-2013, 03:32 PM   #12
Alucarx85
LQ Newbie
 
Registered: Jul 2013
Posts: 6

Rep: Reputation: Disabled
if you work as an admin you need to resolve things quickly. that means you need to find a short way, less type and resolve things faster.

so I would stick with: ps aux|grep -e ]$
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't find my jboss process with ps aux, what is the command to list background proce Niceman2005 Linux - General 3 08-18-2012 06:11 AM
using sed replace command with HTML brackets casperdaghost Linux - Newbie 1 02-25-2012 05:36 PM
square brackets in output of "ps aux" not matching output of "ps -ejH" alirezan1 Linux - Newbie 14 07-14-2010 05:17 AM
syncing two folders where files sourcefiles without brackets[] and target files with Byenary Linux - Networking 0 04-08-2008 03:14 AM
Command to run another command against a list of files psweetma Linux - General 3 11-09-2005 06:29 PM


All times are GMT -5. The time now is 05:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration