6

What is the meaning of this command, what does it do?

ps -aef | grep `pwd`
1
  • 1
    it is probably used to find out processes whose binaries/scripts are located in (or underneath) the current directory. If you start a process with /path/to/the/file , and you go in /path/to, the ps -aef | grep $(pwd) will do a ps -aef | grep /path/to and should show that process as its full path is /path/to/the/file Nov 13, 2013 at 8:21

3 Answers 3

8

From the man page for ps:

   -a              Select all processes except both session leaders (see getsid(2)) and
                   processes not associated with a terminal.

   -f              Do full-format listing. This option can be combined
                   with many other UNIX-style options to add additional
                   columns. It also causes the command arguments to be
                   printed. When used with -L, the NLWP (number of
                   threads) and LWP (thread ID) columns will be added. See
                   the c option, the format keyword args, and the format
                   keyword comm.
   -e              Select all processes. Identical to -A.

grep is used to print lines matching a pattern.

What it does

The command

ps -aef | grep `pwd`

prints out all the lines matching the output of the command pwd(which will be the path your current working directory), from the output of ps -aef.

e.g:

saji@geeklap:~$ pwd
/home/saji

saji@geeklap:~$ ps -aef | grep `pwd`
saji      2854  2814  0 09:51 ?        00:00:00 /usr/bin/ssh-agent /usr/bin/gpg-agent --daemon --sh --write-env-file=/home/saji/.gnupg/gpg-agent-info-geeklap /usr/bin/dbus-launch --exit-with-session gnome-session --session=ubuntu
saji      2855  2814  0 09:51 ?        00:00:00 /usr/bin/gpg-agent --daemon --sh --write-env-file=/home/saji/.gnupg/gpg-agent-info-geeklap /usr/bin/dbus-launch --exit-with-session gnome-session --session=ubuntu
saji      2879     1  0 09:51 ?        00:00:00 /usr/lib/gvfs//gvfs-fuse-daemon -f /home/saji/.gvfs
saji     14242 14148  0 15:26 pts/7    00:00:00 grep --color=auto /home/saji

As you can see the output shows the lines matching my current working directory, which is /home/saji.

Background info:
If a command is in $(...) or ..., then the command is run and the output (what is printed to the screen) is caught and substituted to where the original $() or `` string was. So the actual command run is grep pwd.

For more information refer this link.(Thanks to @minerz029 for this information).

Do check out the following link for a detailed technical answer from the man pages itself:

http://explainshell.com/explain?cmd=ps+-aef+|+grep+%60pwd%60

2
  • 1
    Actually, it does not make sense to use the attribute you have mentioned isn BSD style and with "-" option all the options acts as UNIX option. So the attribute we should be looking at is "-a" which means as below -a Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal.
    – Ajay
    Aug 14, 2019 at 8:32
  • 1
    @Ajay Thanks for pointing out, I have updated the relevant section.
    – saji89
    Aug 14, 2019 at 9:58
3
ps -aef | grep $(pwd)

Searching,Getting and displaying full information about the list of processes which are associated with the working directory and print the path of that directory.

2

ps: Displays information about a selection of the active processes. like ps -e for displaying all current working background processes

I cant understand what is -aef here

grep: Is for searching that specific work within process.

pwd: Print working directory .

I don't think its an useful and meaningful command. May I know for what purpose you are using it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .