Yes, you can copy a file’s full path into a terminal by dragging and dropping the file onto the terminal window. This works on macOS, Linux, and Windows (with some setup), and it saves you from typing long or complicated paths by hand.
Why Drag and Drop Works
Terminal emulators on all major operating systems support a feature called “drag and drop path insertion.� When you drag a file from your file manager (Finder, Nautilus, File Explorer) and drop it into a terminal window, the terminal receives the file’s absolute path as text and inserts it at the cursor position. The path is usually quoted automatically if it contains spaces or special characters, so the shell interprets it as a single argument.
How to Do It on Different Systems
macOS (Terminal, iTerm2)
- Open the Terminal app (or iTerm2).
- Drag any file from Finder into the Terminal window.
- Release the mouse button. The full path appears, often with spaces escaped or quoted.
For example, dragging a file named My Report.pdf from your Desktop might insert /Users/yourname/Desktop/My Report.pdf or /Users/yourname/Desktop/My\ Report.pdf depending on the terminal’s settings.
Linux (GNOME Terminal, Konsole, etc.)
- Open your terminal (e.g., GNOME Terminal).
- Drag a file from the file manager (Files, Dolphin) into the terminal.
- The path appears, usually with spaces escaped or quoted automatically.
Most Linux terminals follow the freedesktop.org drag-and-drop specification, so this works across different desktop environments.
Windows (PowerShell, Command Prompt, Windows Terminal)
- PowerShell: Dragging a file from File Explorer into the PowerShell window inserts the path as a quoted string. Works in Windows Terminal and the classic PowerShell console.
- Command Prompt (cmd): Dragging works in Windows Terminal and in the legacy console, but the path is inserted without quotes. If the path has spaces, you must add quotes yourself.
- Windows Subsystem for Linux (WSL): Dragging a Windows file into a WSL terminal inserts a Windows path like
C:\Users\..., which is not directly usable in Linux. You need to convert it manually or use thewslpathcommand.
What Actually Gets Inserted
The inserted text is the absolute path to the file, meaning it starts from the root directory (e.g., / on Unix-like systems, C:\ on Windows). It does not include the file name only—it includes every parent directory. This is useful because it works regardless of your current working directory in the terminal.
Most terminals automatically escape spaces and special characters (like &, (, )) by adding backslashes or by wrapping the path in quotes. For example:
- On macOS/Linux:
/home/user/My\ Folder/file.txtor"/home/user/My Folder/file.txt" - On Windows PowerShell:
"C:\Users\Me\My Folder\file.txt"
Common Issues and How to Fix Them
Path is not quoted
Some terminals (like older cmd) insert the path without quotes. If the path contains spaces, the shell will treat it as multiple arguments. Solution: after dropping, manually add quotes around the path, or use tab completion to type the path instead.
Dropping onto a running command
If you drop a file while a command is already running (like vim or less), the terminal may insert the path as input to that program, which can cause unexpected behavior. Always drop onto the prompt, not onto a full-screen application.
Dragging from a remote location
Dragging a file from a cloud storage folder (like Google Drive File Stream or OneDrive) may insert a path that is not accessible from the terminal, or a temporary cache path. Check if the path actually exists before using it.
WSL path conversion
In WSL, dragging a Windows file gives a Windows path. To use it in Linux, convert it with wslpath:
wslpath -u 'C:\Users\Me\file.txt'
This outputs /mnt/c/Users/Me/file.txt.
Alternatives to Drag and Drop
If drag and drop is not working or you prefer keyboard methods, here are alternatives:
- Tab completion: Type the beginning of a directory name and press Tab to auto-complete. This is often faster than dragging for short paths.
- Copy and paste: Copy the path from the file manager’s address bar (on Windows/Linux) or from the “Get Info� window (on macOS) and paste it into the terminal.
- pwd command: If the file is in your current directory, type
pwdto see the full path, then append the file name. - find or locate: Use
find / -name "filename"to locate a file and get its path, though this can be slow.
Is It Safe?
Dragging a file into a terminal is safe as long as you know what you are doing. The terminal does not execute the file; it only inserts the path as text. However, if you press Enter after dropping, the command will run. For example, if you drop a path after typing rm, you will delete that file. Always double-check the command before pressing Enter.
Frequently Asked Questions
Why does the path have backslashes before spaces?
Backslashes are escape characters. They tell the shell that the space is part of the file name, not a separator. This is standard on Unix-like systems. On Windows, PowerShell uses backticks or quotes instead.
Can I drag a folder instead of a file?
Yes, dragging a folder inserts its path just like a file. This is often used to navigate to a directory quickly, e.g., cd /path/to/folder.
Does dragging work in all terminal emulators?
Most modern terminal emulators support it, but some minimal or remote terminals (like a bare SSH session) may not. If it doesn’t work, try a different terminal or use copy-paste.
How do I drag a file from a remote server to my local terminal?
You cannot drag a file from a remote server directly. You must first download it to your local machine, then drag it. Alternatively, use scp or SSH to copy the file path manually.
What if I have multiple files selected?
Dragging multiple files at once inserts all their paths, usually space-separated. This is useful for commands like cat file1 file2 or rm file1 file2, but be careful—if a path has spaces, it will be broken unless the terminal quotes each one individually. Test with two files to see how your terminal handles it.
Can I drag a file into the middle of a command I’m typing?
Yes, the path is inserted at the cursor position. You can place the cursor where you want the path to go, then drag the file. This works in most terminals.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Secure Boot Battlefield 6 ASUS: Fix & Enable Guide
- Best Tech Websites to Follow for Pros & Beginners
- Second Wind Quest Walkthrough: Where Winds Meet6.00 min/km
- Enshrouded Weapon Upgrade Guide: How to Improve Gear5.00 min/km
- Connect Phone to Controller for Cloud Gaming
- Python Search Highlighting: Snippets & Matches