If I mount a directory from a remote server on my local machine using sshfs
, how can I find out such details as:
- Whether any such mount is currently mounted;
- The user who mounted it;
- The remote and local directories;
- The time it was mounted at.
mountsshfs
If I mount a directory from a remote server on my local machine using sshfs
, how can I find out such details as:
Best Answer
If the remote directory is mounted, it will be listed in the output of
mount
. That contains most of the information you need:With that in mind, you could write a little script that parses the output and gives you most of the details:
This can be made into a shell function or script, extended to show user name instead of UID and extracting the time from
ps
. This assumes you don't need milliseconds accuracy since the output ofps
refers to when the command was launched and not necessarily when the mount operation ended.If you add the function above to your shell's initialization file (e.g.
~/.bashrc
for bash), you can then run:Note that this assumes only a single sftp instance is running. If you need to deal with multiple instances, use this one instead:
The output looks like:
As you can see in the example above, it can deal with directory names containing spaces as well.
Finally, note that this is not 100% portable. It should work on any system that has the GNU toolset (any Linux distribution, for example) but it won't work on non-GNU systems because it's using features specific to GNU grep.