CAVEAT: you can do the same thing with “lsof” and “fuser”

So you want to see the current files being copied or looked at by cp or rsync (or another program)? So you forgot to do verbose mode and your copy is already running?

You could always restart the copy and have it start back up where it left off… but we all know cp doesnt really do that smoothly, rsync probably does.

Anyhow here is a script that looks at the current open filedescriptors of the pids (of cp, or rsync if you wish) and nicely prints them on the screen. The result is the current files being copied.

Try this: identify the PID of your CP or RSYNC using ps ax . Then do this  find /proc/PID/ -ls  Now look at all of the lines that have the words “/fd/” (file descriptors – or the processes currently opened files )and have an arrow pointing “->”. Everything to the right of that error is where the “/fd/”, file descriptor, is reading from or writing to.

My scripts below just automate that


(- RSYNC-)



What’s happening in the scripts?

First do the “Try this” above the scripts.

First we look for the process with grep thru the list of “ps ax“. We dont want to find the entries of “grep” itself looking for the name of the program, so we avoid that using this trick GREP DONT FIND GREP. After that we look for all of the entries that have “/fd/” because that shows the file-descriptors (open files). Then we look for the stuff to the right of the arrow (the arrow has the unique character “>“, nothing else has that character. Everything to the left of the first “>” would be field 1, but we need field 2 which will give us everything to the right of the first arrow “>“)

Leave a Reply

Your email address will not be published. Required fields are marked *