5

I'm currently changing the permissions and ownership on a 4TB HDD filled with files. Is it even possible to monitor the progress of commands such as chmod and chown?

Adan
  • 153
  • 1
  • 4
  • Is the `-v` flag not enough? – zuazo Dec 09 '16 at 23:11
  • @zuazo It tells the current file that was modified or retained, but since I have an unknown and huge amount of files, I have no idea at what point I'm in the process. I'm a newbie, so any new info is great. Thanks! – Adan Dec 09 '16 at 23:35
  • 4
    Related: [Deleting billions of files from a directory while seeing the progress as well](http://unix.stackexchange.com/questions/327298/deleting-billions-of-files-from-a-directory-while-seeing-the-progress-as-well). See the answer that uses `pv`. – Mark Plotnick Dec 10 '16 at 01:13

4 Answers4

4

You can attach to the running process and see what it's doing now. This will give you an idea of where it's at.

strace -p1234

where 1234 is the process ID of the chmod process. Note that many systems restrict non-root users to monitoring child processes only, so you'd have to do this as root; see after upgrade gdb won't attach to process.

Knowing what file is currently being processed doesn't provide an easy way of knowing what has already been processed. chmod traverses the file tree in depth-first order, and traverses each directory in directory order (the order of ls -U, which is not the same as the order of ls in general).

It would be nice to know how many files the process has already processed, and that can be determined at least approximately by knowing how many system calls the process has made, but as far as I know Linux doesn't keep track of how many system calls a process has made.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • The problem is that I'm using a recursive chmod, so it changes the pid continuously. – Adan Dec 14 '16 at 00:44
  • @vasc0x No, a recursive chmod (`chmod -R`) does not fork, so there is only one PID. If you ran `find … -exec chmod … {} \;` then that does invoke one `chmod` per file; you can find where the recursion is at by tracing the `find` process. – Gilles 'SO- stop being evil' Dec 14 '16 at 00:59
1

In general, no, not without some flag to show what a program is doing, with the flag being specified when the process launched. (If you do make it verbose, also be sure to put it in a screen or tmux session so you can reconnect to that as necessary...)

Some utilities (e.g. dd) accept a user signal to toggle verbosity (e.g. via the USR1 signal, pkill -USR1 dd) but that varies by application (USR1 by default just kills a process; use with caution).

Indirect indications are another method, e.g. run top, assuming the processes generates sufficient CPU or I/O load to make it stand out (something that waits on network results may not appear to be doing much).

Process tracing is also possible, though may horribly slow the system down (e.g. strace); less expensive tools for such a check would be dtrace or similar which can take samples and report a summary on how many relevant system calls chmod is making over some duration.

thrig
  • 34,333
  • 3
  • 63
  • 84
1
chmod $(whoami) -Rv /my/folder | pv --line-mode > /dev/null
  • -R - recursively chown folder's content
  • -v - print diagnostics for every file or directory
  • pv --line-mode - counts processed files and folders (their diagnostic lines)
  • > /dev/null - discards diagnostic data
tldr
  • 11
  • 1
0

You might look at the pv command. I don't have it on this system at the moment, but it helps you monitor pipe flows.

I am assuming you are doing something like:

find stuff -exec chmod 664 {} \;

You could break up the command using pipes, and then insert pv or tee in to monitor where things were at.

I realize that I didn't cookbook an answer, but perhaps these ideas will help.

user
  • 28,161
  • 13
  • 75
  • 138
mongo
  • 141
  • 6