Command line command to refresh GUI desktop, like when pressing F5?

Is there any command to refresh the desktop icons (exactly like F5 button does)?

I need this because in Startup Applications I set a command to mount my backup partition and I've created a desktop link to some directories there. The problem is that the icons are not refreshed when I log in, unless I press F5. I would like to put a command in the Startup Applications to do so. (note that I don't want to restart the GNOME shell or Unity, like they said here. I just need a command to do exactly what F5 does)


You could emulate pressing the key with xdotool, if you can not find how to directly call the function it is mapped to:

xdotool key F5

The difficult part is to do that when the current window is not the desktop.
It should be possible to find it with th search command - but may need some experimenting;

First, try to find the right window, using getwindowname to show the title of matched windows:

xdotool search --class Desktop getwindowname

If the result looks right, try:

xdotool search --class Desktop key F5

Otherwise, see man xdotool for many more options of xdotool search.
If you need more information about the existing windows to make it work, these commands are the most useful for inspecting them: xwininfo and xprop.


If refreshing is tricky, we can restart Nautilus:

pkill nautilus
nautilus -n

Your Startup Applications entry can be easily modified to add these commands as well, as part of script, by chaining:

udisks --mount  ... && pkill -u nautilus && nautilus -n

Nautilus has a -q option to make it quit by itself, but this doesn't work well with nautilus -n.