Take the 2-minute tour ×

Is there a way to find what path a command has had it's output redirected to (if it has been)?

I tried using:

ps -p PID -o cmd

Thinking I could look for a > and extract the path from that, but the output doesn't have that part in it. I'm pretty sure it hasn't just been truncated.

share|improve this question
add comment

4 Answers

up vote 2 down vote accepted

You can use the proc file system /proc/self/fd for this

readlink /proc/self/fd/1

for stdout or 2 for stderr.

share|improve this answer
add comment

If you know the PID, just inspect /proc/ID/fd/1. It should be linked to the actual path:

$ watch date > /tmp/1 &
[1] 27346
$ ls -l /proc/27346/fd/1
l-wx------ 1 choroba users 64 2013-02-15 16:28 /proc/27346/fd/1 -> /tmp/1
share|improve this answer
add comment

Use the lsof (list open files) command to see what files a process has open for writing.

For example:

$ lsof -p 31714
bash    31714 dogbane    0u   CHR  136,4                  6 /dev/pts/4
bash    31714 dogbane    1w   REG    8,1      15    2032202 /tmp/t

The w in the FD (file descriptor) column means that /tmp/t is open for writing.

share|improve this answer
add comment

How about it?

[root@us04 ~]# ls -l /proc/14170/exe
lrwxrwxrwx 1 root root 0 Feb 15 10:36 /proc/14170/exe -> /usr/sbin/httpd

One more example:

[root@us04 ~]# readlink -f /proc/5352/exe
share|improve this answer
add comment

Your Answer


