82

How can I copy the file and folders full path in Nautilus? In the right-click context menu there is no such option provided. In file/folder property window I can only copy the folder path.

Braiam
  • 67,791
  • 32
  • 179
  • 269

10 Answers10

100

To quickly get a file path in Nautilus we can use the right click context entry "Copy" to copy the file path to the clipboard.

Then just "Paste" (resp. "Paste Filenames") this path from the clipboard to the other application, e.g. a text editor.

Takkat
  • 142,284
  • Wow, this actually works, thanks for the great tip! – Gerhard Burger Dec 05 '12 at 08:58
  • 7
    Context-aware pasting, so awesome! – Alix Axel Aug 01 '13 at 17:07
  • 11
    Unfortunately in Ubuntu 12.04 this does not work flawlessly. When I paste to GNOME Terminal I get URL i.e. file:\\... (with URL encoded characters like %20 for space) instead of the ordinary path. – pabouk - Ukraine stay strong Aug 03 '13 at 20:03
  • 6
    @pabouk as a workaround you can drag and drop files onto the GNOME terminal. This will paste the file path instead of its URI. – Glutanimate Aug 04 '13 at 00:25
  • 2
    That was a bit too simple... thank you so much for the tips! Copying manually the name since years! – Gabriel Klein Dec 02 '16 at 15:09
  • 3
    This does not work in 20.04.2 (nautilus 3.36.3). When I copy and past, I get x-special/nautilus-clipboard copy file:///.... It used to work in previous versions... – moi May 05 '21 at 19:55
  • 2
    This works only on the terminal, in the way @moi described it, in my system: in Ubuntu 20.04.3 LTS, Files 3.36.3-stable. It doesn't paste the filename in my browser, which is not good, since copy-paste traditionally always has worked in the same way no matter where you are. – Santropedro Sep 17 '21 at 20:52
  • Doesn't work for VS Code – dvdhns Dec 06 '22 at 03:53
  • –1 This answer does not actually work. E.g., select file, right click and select Copy (alternately -C), then try and paste, e.g., in RStudio. Nada. – Lexible Sep 29 '23 at 19:12
49

You can use to copy folder path from Nautilus with the command

Ctrl + l

IgorBeaz
  • 636
19

Unfortunately pasting file path from Nautilus to GNOME Terminal does not work as expected. It pastes the path as an URL with URL encoded characters. For example it pastes:

 file:///etc/gconf/gconf.xml.defaults/%25gconf-tree.xml

instead of

 /etc/gconf/gconf.xml.defaults/%gconf-tree.xml

Solution with clipboard

Use the Edit > Paste Filenames function from the terminal menu which also takes care of escaping for a shell. Unfortunately this function does not have a keyboard shortcut (besides Alt+E+F) and it seems that it is not possible to set one using gconf-editor.

See also Nautilus copy file/directory path should not put "file://" prefix.

Solution with drag & drop

Dragging a file or directory from Nautilus to GNOME Terminal transfers the correctly formatted path like Edit > Paste Filenames mentioned above.

  • This is resolved in Ubuntu 16.04. Copying a file from Nautilus to GNOME Terminal will just give the path /path/to/file, not the URL. – wisbucky Jul 26 '18 at 20:39
  • 6
    In Ubuntu 20.04 this is definitely not resolved (or the bug is back?) You get terrible gunk: x-special/nautilus-clipboardcopyfile://file. – Kvothe Nov 19 '20 at 13:41
4

I found a solution to this. You can use Nautilus actions utility to add "Copy path" and "Copy directory path" the the context menu.

This seems to work well.

Source. Don't forget to make the .py-file executable.

MrTomRod
  • 141
Aaron
  • 49
  • 1
  • The other answers already said it copies as a path by default, this method is unnecessary – kiri Sep 07 '13 at 00:18
2

Since Takkat's solution seems to be broken with Nautilus version >= 3.30 (bug report), I would like to offer a workaround that creates a context menu option.

  1. Install Filemanager-Actions, and xclip:

sudo apt-get install filemanager-actions nautilus-actions xclip

  1. Run FileManager-Actions, and create a new action like so:
  • Hit button "Define a new action"
  • Name the action in the "Items list", e.g. "Copy path to clipboard"
  • Under the "Action" tab, check the two options "Display item in selection context menu", and "Display item in location context menu"
  • Under the "Command" tab, set path to "bash", and "Parameters" to

-c "realpath -z %B | xclip -selection clipboard"

  • Hit the button "save the items tree"
  • restart nautilus: "nautilus -q"
  1. Now you should be able to right click a file/folder, and see the action we just defined to copy the path
1

Simply sudo apt-get install pcmanfm, open it, choose 'keep in Unity starts' and finally remove Nautilus.

The logo is the same, you won't notice the difference - except that you can now copy the path..

0

Create the file and make executable

sudo touch /usr/share/nautilus-python/extensions/nautilus-copy-paths.py
sudo chmod +x /usr/share/nautilus-python/extensions/nautilus-copy-paths.py
sudo gedit /usr/share/nautilus-python/extensions/nautilus-copy-paths.py
nautilus -q

then when editing past i the below content and restart nautilus afterwards

import os
from gi import require_version
require_version('Gtk', '3.0')
require_version('Nautilus', '3.0')

from gi.repository import Gdk, Gtk, Nautilus, GObject from gettext import gettext, bindtextdomain, textdomain

NAUTILUS_PATH="/usr/bin/nautilus"

class NautilusAdmin(Nautilus.MenuProvider, GObject.GObject): """Simple Nautilus extension that adds some file path actions to the right-click menu, using GNOME's new admin backend.""" def init(self): pass

def get_file_items(self, window, files):
    """Returns the menu items to display when one or more files/folders are
    selected."""
    # Don't show when more than 1 file is selected
    if len(files) != 1:
        return
    file = files[0]

    # Add the menu items
    items = []
    self._setup_gettext();
    self.window = window
    if file.get_uri_scheme() == "file": # must be a local file/directory
        if file.is_directory():
            if os.path.exists(NAUTILUS_PATH):
                items += [self._create_nautilus_item(file)]

    return items

def get_background_items(self, window, file):
    """Returns the menu items to display when no file/folder is selected
    (i.e. when right-clicking the background)."""

    # Add the menu items
    items = []
    self._setup_gettext();
    self.window = window
    if file.is_directory() and file.get_uri_scheme() == "file":
        if os.path.exists(NAUTILUS_PATH):
            items += [self._create_nautilus_item(file)]

    return items


def _setup_gettext(self):
    """Initializes gettext to localize strings."""
    try: # prevent a possible exception
        locale.setlocale(locale.LC_ALL, "")
    except:
        pass
    bindtextdomain("nautilus-admin", "/usr/share/locale")
    textdomain("nautilus-admin")

def _create_nautilus_item(self, file):
    item = Nautilus.MenuItem(name="NautilusAdmin::Nautilus",
                             label=gettext("Copy path"),
                             tip=gettext("Copy File path to clipboard"))
    item.connect("activate", self._nautilus_run, file)
    return item



def _nautilus_run(self, menu, file):
    """'Copy File path' menu item callback."""
    uri = file.get_uri()
    file_path = uri.replace("file://", "")
    clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
    clipboard.set_text(file_path, -1)
    clipboard.store()

I just modified the source from this extensions which does work to do what I wanted. https://fostips.com/open-as-administrator-ubuntu-21-04-fix/

Example: enter image description here

hope this is helpful

Mike R
  • 121
  • Thank you for this, but it doesn't seem to work correctly on ubuntu 22. – electrode Jun 27 '23 at 01:15
  • Been working for me still on Ubuntu 22.04 based PopOS since setup. Any specific errors your seeing when your trying to setup? – Mike R Sep 11 '23 at 12:53
0

The functionality to copy a file path has changed (i.e., for practical purposes, broken) since 20.04 to accommodate requirements to work with the Desktop Icons Gnome Shell extension. The good news is that the old behaviour, where a copy will place plain file path in the clipboard, is restored in Files 40.0. Files 40 which will make it into Ubuntu 21.10, rendering the accepted answer of this question valid again.

vanadium
  • 88,010
0

Rather than nautilius, you can use the following command if you have copyq clipboard.

copyq add "`pwd`"

This will copy the current path to the clipboard, then basically you can paste and use it anywhere you want.

malachi
  • 21
0

Nautilus does not provide this possibility.
But it should be possible to achieve this if you write a plugin for Nautilus.