4

When I copy, move, or delete a file in Nautilus or using the corresponding commands (cp, mv, or rm) does the same tool perform the action behind the wraps?

I ask because nautilus tends to hang on big files or too many files. I have the impression that it's not that efficient.

  • 1
    I haven't looked at the source but almost certainly not. Implementing these functions in native C would be simpler than importing stuff from other projects, and executing cp etc. as subprocesses would be absurdly unwieldy WRT controlling their behavior. – goldilocks Dec 30 '13 at 20:45
4

No it doesn't just make calls to cp, mv, etc.

Rather, it makes calls to a GTK+ library that contains wrapper functions around C/C++ system libraries that also contain functions. It is these C/C++ functions that are shared across Nautilus and commands such as cp, mv, etc.

Example

You can use the system tracing tool strace to attach to a running nautilus process like so:

$ strace -Ff -tt -p $(pgrep nautilus) 2>&1 | tee strace-naut.log

Now if we perform some operations within Nautilus we'll see the system calls that are being made. Here's a sampling of the logs during the copy/paste of file /home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz.

[pid 25897] 22:28:36.909183 lstat("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", {st_mode=S_IFREG|0664, st_size=16090900, ...}) = 0
[pid 25897] 22:28:36.909259 access("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", R_OK) = 0
[pid 25897] 22:28:36.909302 access("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", W_OK) = 0
[pid 25897] 22:28:36.909339 access("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", X_OK) = -1 EACCES (Permission denied)
[pid 25897] 22:28:37.580109 lstat("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", {st_mode=S_IFREG|0664, st_size=16090900, ...}) = 0
[pid 25897] 22:28:37.580169 access("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", R_OK) = 0
[pid 25897] 22:28:37.580215 access("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", W_OK) = 0
[pid 25897] 22:28:37.580249 access("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", X_OK) = -1 EACCES (Permission denied)
[pid 26667] 22:28:39.222446 lstat("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", {st_mode=S_IFREG|0664, st_size=16090900, ...}) = 0
[pid 26667] 22:28:39.222981 lstat("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", {st_mode=S_IFREG|0664, st_size=16090900, ...}) = 0
[pid 26667] 22:28:39.223201 lstat("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", {st_mode=S_IFREG|0664, st_size=16090900, ...}) = 0
[pid 26667] 22:28:39.223304 lstat("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", {st_mode=S_IFREG|0664, st_size=16090900, ...}) = 0
[pid 26667] 22:28:39.223397 lstat("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", {st_mode=S_IFREG|0664, st_size=16090900, ...}) = 0
[pid 26667] 22:28:39.223444 open("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06.tar.gz", O_RDONLY) = 46
[pid 26667] 22:28:39.223658 open("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06 (copy).tar.gz", O_WRONLY|O_CREAT|O_EXCL, 0664) = 47
[pid 25897] 22:28:39.235249 read(14, "\f\0\0\0\0\1\0\0\0\0\0\0000\0\0\0ULD_Linux_V1.00."..., 1024) = 96
[pid 26667] 22:28:39.388744 lstat("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06 (copy).tar.gz",  <unfinished ...>
[pid 26667] 22:28:39.388853 chmod("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06 (copy).tar.gz", 0100664 <unfinished ...>
[pid 26667] 22:28:39.388959 stat("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06 (copy).tar.gz",  <unfinished ...>
[pid 26667] 22:28:39.389061 utimes("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06 (copy).tar.gz", {{1388460519, 222672}, {1384901700, 0}} <unfinished ...>
[pid 26667] 22:28:39.391274 lstat("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06 (copy).tar.gz",  <unfinished ...>
[pid 26667] 22:28:39.391848 access("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06 (copy).tar.gz", R_OK <unfinished ...>
[pid 26667] 22:28:39.391955 access("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06 (copy).tar.gz", W_OK <unfinished ...>
[pid 26667] 22:28:39.392059 access("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06 (copy).tar.gz", X_OK <unfinished ...>
[pid 26667] 22:28:39.392734 lgetxattr("/home/saml/samsung_ml2165w_print_drivers/ULD_Linux_V1.00.06 (copy).tar.gz", "security.selinux" <unfinished ...>

The system calls, lstat, access, open, read, etc. are the lower level calls that would be in common.

1

Just by observing its behavior, Nautilus definitely does some magic in the background, for example:

  • Deleting files is typically not an rm, but moving to a Trash folder somewhere
  • Copying files has a fancy progress tracker
  • Moving files across partitions (which is really a copy operation) also has a fancy progress tracker
  • ...

So yeah, if speed is important to you, nothing beats the command line. You could also create Nautilus scripts that don't use all the bells and whistles, just run the appropriate shell commands and nothing else.

  • Nautilus could use the same tools and then inspect /proc for progression status. – Spidey Dec 30 '13 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.