🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 18 (from laksa045)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
CRAWLED
15 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.5 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard
Last Crawled2026-04-01 11:01:57 (15 days ago)
First Indexed2020-08-30 00:35:19 (5 years ago)
HTTP Status Code200
Meta Titlemac - How to use terminal to copy a file to the clipboard? - Ask Different
Meta Descriptionnull
Meta Canonicalnull
Boilerpipe Text
There is no way to achieve what you are trying to do using the command line. While Apple offers the pbcopy and pbpaste tools to allow basic copying of text, you cannot use these tools to copy a file in the sense you're looking for. Without going in to too much technical detail, when you 'copy' a file in the Finder using ⌘ C , you're not actually copying the file itself, just making a reference to the file on the clipboard and marking it as a file reference. When an application receives this reference when you paste, it has the responsibility of sorting things out, figuring out what you pasted, and ultimately, working with the file as it sees fit. In essence, when you copy a file in the Finder, it saves the path to the file in a certain way to a certain clipboard, and when you paste, it receives that file path and knows to create a new file using the contents of the old one (copy a file to the clipboard, delete it, try to paste it somewhere else, and see what happens, for instance). In this sense of copying and pasting, the tools available at hand are not enough to do what you need. As boehj suggested, you can try to copy the contents of the old file into a new one, but this will only work well for text files. Any binary files you get will be corrupted (try doing this with an image – it becomes corrupted). The traditional command line will fail you in this way, but you can take a look if you'd like into doing this in AppleScript, then invoking that through the command line with osascript .
Markdown
# ![site logo](https://stackoverflow.com/Content/Img/SE-logo75.png) By clicking “Sign up”, you agree to our [terms of service](https://apple.stackexchange.com/legal/terms-of-service/public) and acknowledge you have read our [privacy policy](https://apple.stackexchange.com/legal/privacy-policy). # OR Already have an account? [Log in](https://apple.stackexchange.com/users/login) [Skip to main content](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#content) #### Stack Exchange Network Stack Exchange network consists of 183 Q\&A communities including [Stack Overflow](https://stackoverflow.com/), the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. [Visit Stack Exchange](https://stackexchange.com/) 1. - [Tour Start here for a quick overview of the site](https://apple.stackexchange.com/tour) - [Help Center Detailed answers to any questions you might have](https://apple.stackexchange.com/help) - [Meta Discuss the workings and policies of this site](https://apple.meta.stackexchange.com/) - [About Us Learn more about Stack Overflow the company, and our products](https://stackoverflow.co/) 2. ### [current community](https://apple.stackexchange.com/) - [Ask Different](https://apple.stackexchange.com/) [help](https://apple.stackexchange.com/help) [chat](https://chat.stackexchange.com/?tab=site&host=apple.stackexchange.com) - [Ask Different Meta](https://apple.meta.stackexchange.com/) ### your communities [Sign up](https://apple.stackexchange.com/users/signup?ssrc=site_switcher&returnurl=https%3A%2F%2Fapple.stackexchange.com%2Fquestions%2F15318%2Fhow-to-use-terminal-to-copy-a-file-to-the-clipboard) or [log in](https://apple.stackexchange.com/users/login?ssrc=site_switcher&returnurl=https%3A%2F%2Fapple.stackexchange.com%2Fquestions%2F15318%2Fhow-to-use-terminal-to-copy-a-file-to-the-clipboard) to customize your list. ### [more stack exchange communities](https://stackexchange.com/sites) [company blog](https://stackoverflow.blog/) 3. [Log in](https://apple.stackexchange.com/users/login?ssrc=head&returnurl=https%3A%2F%2Fapple.stackexchange.com%2Fquestions%2F15318%2Fhow-to-use-terminal-to-copy-a-file-to-the-clipboard) 4. [Sign up](https://apple.stackexchange.com/users/signup?ssrc=head&returnurl=https%3A%2F%2Fapple.stackexchange.com%2Fquestions%2F15318%2Fhow-to-use-terminal-to-copy-a-file-to-the-clipboard) [![Ask Different](https://apple.stackexchange.com/Content/Sites/apple/Img/logo.svg?v=3dfcc68bd7ee)](https://apple.stackexchange.com/) 1. 1. [Home](https://apple.stackexchange.com/) 2. [Questions](https://apple.stackexchange.com/questions) 3. [Unanswered](https://apple.stackexchange.com/unanswered) 4. [AI Assist](https://stackoverflow.com/ai-assist) 5. [Tags](https://apple.stackexchange.com/tags) 6. [Chat](https://chat.stackexchange.com/) 7. [Users](https://apple.stackexchange.com/users) 8. [Companies](https://stackoverflow.com/jobs/companies?so_medium=apple&so_source=SiteNav) 2. Stack Internal Stack Overflow for Teams is now called **Stack Internal**. Bring the best of human thought and AI automation together at your work. [Try for free](https://stackoverflowteams.com/teams/create/free/?utm_medium=referral&utm_source=apple-community&utm_campaign=side-bar&utm_content=explore-teams) [Learn more](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=apple-community&utm_campaign=side-bar&utm_content=explore-teams) 3. [Stack Internal]() 4. Bring the best of human thought and AI automation together at your work. [Learn more](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=apple-community&utm_campaign=side-bar&utm_content=explore-teams-compact) **Stack Internal** Knowledge at work Bring the best of human thought and AI automation together at your work. [Explore Stack Internal](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=apple-community&utm_campaign=side-bar&utm_content=explore-teams-compact-popover) # [How to use terminal to copy a file to the clipboard?](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard) [Ask Question](https://apple.stackexchange.com/questions/ask) Asked 14 years, 10 months ago Modified [3 years, 1 month ago](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard?lastactivity "2023-02-09 15:59:46Z") Viewed 274k times This question shows research effort; it is useful and clear 285 Save this question. Show activity on this post. I got a file on desktop, file name is ded.html. To copy the file, I click the file and press cmd+c. Now how would I do the same thing using terminal ? - [mac](https://apple.stackexchange.com/questions/tagged/mac "show questions tagged 'mac'") - [terminal](https://apple.stackexchange.com/questions/tagged/terminal "show questions tagged 'terminal'") [Share](https://apple.stackexchange.com/q/15318 "Short permalink to this question") Share a link to this question Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this question](https://apple.stackexchange.com/posts/15318/edit) Follow Follow this question to receive notifications [edited Aug 21, 2020 at 4:01](https://apple.stackexchange.com/posts/15318/revisions "show all edits to this post") [![Community's user avatar](https://www.gravatar.com/avatar/a007be5a61f6aa8f3e85ae2fc18dd66e?s=64&d=identicon&r=PG)](https://apple.stackexchange.com/users/-1/community) [Community](https://apple.stackexchange.com/users/-1/community)Bot 1 asked Jun 5, 2011 at 7:55 [![angry kiwi's user avatar](https://www.gravatar.com/avatar/0f96ec6ae10d20f4c2fc756139dcd097?s=64&d=identicon&r=PG)](https://apple.stackexchange.com/users/6945/angry-kiwi) [angry kiwi](https://apple.stackexchange.com/users/6945/angry-kiwi) 3,13555 gold badges2121 silver badges2020 bronze badges 2 - 4 Do you mean copy the file or copy the contents of the file so that the contents can be pasted? mmmmmm – [mmmmmm](https://apple.stackexchange.com/users/237/mmmmmm "31,477 reputation") 2011-06-09 22:51:01 +00:00 [Commented Jun 9, 2011 at 22:51](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment17079_15318) - 1 Also see [apple.stackexchange.com/q/362245/10713](https://apple.stackexchange.com/q/362245/10713) laktak – [laktak](https://apple.stackexchange.com/users/10713/laktak "3,257 reputation") 2019-06-12 19:38:04 +00:00 [Commented Jun 12, 2019 at 19:38](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment480784_15318) [Add a comment](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard "Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.") \| ## 11 Answers 11 Sorted by: [Reset to default](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard?answertab=scoredesc#tab-top) This answer is useful 413 Save this answer. Show activity on this post. If I'm understanding the question right, what you're after is `pbcopy` and `pbpaste`. Open a terminal and run: ``` cat ~/Desktop/ded.html | pbcopy ``` The file is now in your clipboard. To put it somewhere else (i.e. paste it) run: ``` pbpaste > ~/Documents/ded.html ``` Now you should have a copy of ded.html sitting in ~/Documents. [Share](https://apple.stackexchange.com/a/15322 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://apple.stackexchange.com/posts/15322/edit) Follow Follow this answer to receive notifications [edited Aug 21, 2020 at 4:01](https://apple.stackexchange.com/posts/15322/revisions "show all edits to this post") [![Community's user avatar](https://www.gravatar.com/avatar/a007be5a61f6aa8f3e85ae2fc18dd66e?s=64&d=identicon&r=PG)](https://apple.stackexchange.com/users/-1/community) [Community](https://apple.stackexchange.com/users/-1/community)Bot 1 answered Jun 5, 2011 at 10:33 [![boehj's user avatar](https://www.gravatar.com/avatar/d9a10e6ca7006e1da54fe7eac1953880?s=64&d=identicon&r=PG)](https://apple.stackexchange.com/users/2190/boehj) [boehj](https://apple.stackexchange.com/users/2190/boehj) 6,18955 gold badges3030 silver badges2929 bronze badges 6 - 9 This is great for working with text files, but will fail when you try to perform the task with binaries. Try this out with an image to see what I mean. Itai Ferber – [Itai Ferber](https://apple.stackexchange.com/users/1648/itai-ferber "556 reputation") 2011-06-05 11:51:54 +00:00 [Commented Jun 5, 2011 at 11:51](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment16613_15322) - 9 after typing \$ cat ~/Desktop/ded.html \| pbcopy I can not use cmd+v to paste the file. Althought \$ pbpaste \> ~/Documents/ded.html did the job. angry kiwi – [angry kiwi](https://apple.stackexchange.com/users/6945/angry-kiwi "3,135 reputation") 2011-06-05 13:02:14 +00:00 [Commented Jun 5, 2011 at 13:02](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment16621_15322) - 4 You can also view the file contents in your OSX clipboard by going through the Finder menu *Edit \> Show Clipboard* (tested in Yosemite). Dannid – [Dannid](https://apple.stackexchange.com/users/62453/dannid "532 reputation") 2015-08-11 19:37:23 +00:00 [Commented Aug 11, 2015 at 19:37](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment240645_15322) - 7 This copies the contents of the file, but not the file itself. vy32 – [vy32](https://apple.stackexchange.com/users/10467/vy32 "3,574 reputation") 2019-03-08 03:24:48 +00:00 [Commented Mar 8, 2019 at 3:24](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment465541_15322) - 6 `pbcopy < ~/Desktop/ded.html` is OK DawnSong – [DawnSong](https://apple.stackexchange.com/users/173372/dawnsong "123 reputation") 2019-07-15 05:27:22 +00:00 [Commented Jul 15, 2019 at 5:27](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment485341_15322) \| [Show **1** more comment](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard "Expand to show all comments on this post") This answer is useful 33 Save this answer. Show activity on this post. [Lri’s answer](https://apple.stackexchange.com/questions/15318/using-terminal-to-copy-a-file-to-clipboard/15484#15484) is headed in the right direction, but it has a couple of flaws: there is no need to use *Finder* (`the clipboard` is part of the *StandardAdditions* OSAX), and giving a `run` handler is a much more reliable way to pass arguments from the command line (since 10.4). Making both of these changes greatly simplifies the “escaping” that needs to be done to enter the program in a shell. Here is my version (wrapped in a shell function—you could put this in (e.g.) your `.bashrc` to make it available in your shells): ``` file-to-clipboard() { osascript \ -e 'on run args' \ -e 'set the clipboard to POSIX file (first item of args)' \ -e end \ "$@" } file-to-clipboard ~/Desktop/ded.html ``` A file that has been put on the clipboard with this script can then be pasted in *Finder* to copy the file to another folder. *osascript* can also be used as a hash-bang interpreter (since 10.5). Put this in a file (e.g. `file-to-clipboard`) ``` #!/usr/bin/osascript on run args set the clipboard to POSIX file (first item of args) end ``` Make the file executable (`chmod +x /path/to/where/ever/you/put/file-to-clipboard`). Then run it like so: ``` /path/to/where/ever/you/put/file-to-clipboard ~/Desktop/ded.html ``` If it is stored in a directory in the PATH, then you can omit the path to the “script” file. [Share](https://apple.stackexchange.com/a/15542 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://apple.stackexchange.com/posts/15542/edit) Follow Follow this answer to receive notifications [edited Apr 13, 2017 at 12:45](https://apple.stackexchange.com/posts/15542/revisions "show all edits to this post") [![Community's user avatar](https://www.gravatar.com/avatar/a007be5a61f6aa8f3e85ae2fc18dd66e?s=64&d=identicon&r=PG)](https://apple.stackexchange.com/users/-1/community) [Community](https://apple.stackexchange.com/users/-1/community)Bot 1 answered Jun 8, 2011 at 3:44 [![Chris Johnsen's user avatar](https://www.gravatar.com/avatar/c8134b3aced69c76a88722e3d36ba034?s=64&d=identicon&r=PG)](https://apple.stackexchange.com/users/3349/chris-johnsen) [Chris Johnsen](https://apple.stackexchange.com/users/3349/chris-johnsen) 4,59122 gold badges3131 silver badges3030 bronze badges 8 - @Lri: Finder does not understand the obvious `set the clipboard to {one,two}` (though another AppleScript program can successfully extract the list). The *StandardAdditions* clipboard commands may be limited to single items. Chris Johnsen – [Chris Johnsen](https://apple.stackexchange.com/users/3349/chris-johnsen "4,591 reputation") 2011-06-08 23:10:47 +00:00 [Commented Jun 8, 2011 at 23:10](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment16986_15542) - 1 Would it work for multiple files? VitalyB – [VitalyB](https://apple.stackexchange.com/users/172686/vitalyb "101 reputation") 2016-03-02 23:25:27 +00:00 [Commented Mar 2, 2016 at 23:25](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment280057_15542) - 3 Note: The path given has to be an absolute path for the script to work. Leo – [Leo](https://apple.stackexchange.com/users/47975/leo "101 reputation") 2019-09-14 01:22:43 +00:00 [Commented Sep 14, 2019 at 1:22](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment495445_15542) - Works for any kind of file, not just text files (unlike pbcopy/bypase)! Convenient if you need to copy an image file. 0xZ3RR0 – [0xZ3RR0](https://apple.stackexchange.com/users/193408/0xz3rr0 "345 reputation") 2020-10-21 10:04:42 +00:00 [Commented Oct 21, 2020 at 10:04](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment561933_15542) - 1 Hi, I tried this answer, the picture can't paste to microsoft word, but can be paste into finder,(in normal,copy a image can either paste to word, a textEdit or finder),can you help more? user956609 – [user956609](https://apple.stackexchange.com/users/361787/user956609 "425 reputation") 2021-04-07 14:49:59 +00:00 [Commented Apr 7, 2021 at 14:49](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment586718_15542) \| [Show **3** more comments](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard "Expand to show all comments on this post") This answer is useful 15 Save this answer. Show activity on this post. Executing `pbcopy < filename` command in the Terminal copies the contents of the file named `filename`. [Share](https://apple.stackexchange.com/a/322317 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://apple.stackexchange.com/posts/322317/edit) Follow Follow this answer to receive notifications [edited Apr 12, 2018 at 15:41](https://apple.stackexchange.com/posts/322317/revisions "show all edits to this post") [![Nimesh Neema's user avatar](https://i.sstatic.net/ZLQFVTCm.png?s=64)](https://apple.stackexchange.com/users/279727/nimesh-neema) [Nimesh Neema](https://apple.stackexchange.com/users/279727/nimesh-neema)♦ 54\.5k2626 gold badges163163 silver badges220220 bronze badges answered Apr 12, 2018 at 13:59 [![shinxg's user avatar](https://i.sstatic.net/ziIsH.png?s=64)](https://apple.stackexchange.com/users/285131/shinxg) [shinxg](https://apple.stackexchange.com/users/285131/shinxg) 25122 silver badges44 bronze badges 2 - 1 10x easier than the accepted answer Paul Razvan Berg – [Paul Razvan Berg](https://apple.stackexchange.com/users/246279/paul-razvan-berg "461 reputation") 2019-12-07 18:56:15 +00:00 [Commented Dec 7, 2019 at 18:56](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment508160_322317) - 2 Yes, but as mentioned—does not work for images or binaries. luckman212 – [luckman212](https://apple.stackexchange.com/users/100302/luckman212 "4,085 reputation") 2021-02-19 19:24:04 +00:00 [Commented Feb 19, 2021 at 19:24](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment579529_322317) [Add a comment](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful 14 Save this answer. Show activity on this post. There is no way to achieve what you are trying to do using the command line. While Apple offers the `pbcopy` and `pbpaste` tools to allow basic copying of text, you cannot use these tools to copy a file in the sense you're looking for. Without going in to too much technical detail, when you 'copy' a file in the Finder using `⌘``C`, you're not actually copying the file itself, just making a reference to the file on the clipboard and marking it as a file reference. When an application receives this reference when you paste, it has the responsibility of sorting things out, figuring out what you pasted, and ultimately, working with the file as it sees fit. In essence, when you copy a file in the Finder, it saves the path to the file in a certain way to a certain clipboard, and when you paste, it receives that file path and knows to create a new file using the contents of the old one (copy a file to the clipboard, delete it, try to paste it somewhere else, and see what happens, for instance). In this sense of copying and pasting, the tools available at hand are not enough to do what you need. As boehj suggested, you can try to copy the contents of the old file into a new one, but this will only work well for text files. Any binary files you get will be corrupted (try doing this with an image – it becomes corrupted). The traditional command line will fail you in this way, but you can take a look if you'd like into doing this in AppleScript, then invoking that through the command line with `osascript`. [Share](https://apple.stackexchange.com/a/15327 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://apple.stackexchange.com/posts/15327/edit) Follow Follow this answer to receive notifications [edited Jun 5, 2011 at 11:55](https://apple.stackexchange.com/posts/15327/revisions "show all edits to this post") answered Jun 5, 2011 at 11:49 [![Itai Ferber's user avatar](https://www.gravatar.com/avatar/eb61781f55bda1790e6216a2dee08b11?s=64&d=identicon&r=PG)](https://apple.stackexchange.com/users/1648/itai-ferber) [Itai Ferber](https://apple.stackexchange.com/users/1648/itai-ferber) 55622 silver badges1111 bronze badges 0 [Add a comment](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful 13 Save this answer. Show activity on this post. The function below only works with a single file and not with multiple files. It requires GNU `readlink` which you can install by running `brew install findutils`. ``` copy(){ osascript -e{'on run{a}','set the clipboard to posix file a',end} "$(greadlink -f -- "$1")";} ``` Edit: I removed the `tell app "Finder"` block. Edit 2: Reverted back to a version which supports relative paths. [Share](https://apple.stackexchange.com/a/15484 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://apple.stackexchange.com/posts/15484/edit) Follow Follow this answer to receive notifications [edited May 10, 2019 at 4:58](https://apple.stackexchange.com/posts/15484/revisions "show all edits to this post") answered Jun 7, 2011 at 12:46 [![Lri's user avatar](https://www.gravatar.com/avatar/16bbc7f782efd1c489a0d0d9e6075291?s=64&d=identicon&r=PG)](https://apple.stackexchange.com/users/3936/lri) [Lri](https://apple.stackexchange.com/users/3936/lri) 108k2020 gold badges234234 silver badges285285 bronze badges 2 - 2 This one actually works\! Bemmu – [Bemmu](https://apple.stackexchange.com/users/71341/bemmu "525 reputation") 2016-03-03 00:36:02 +00:00 [Commented Mar 3, 2016 at 0:36](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment280071_15484) - I would guess `greadlink` is no longer necessary since Apple's`/usr/bin/readlink` now supports `-f`. I'm using Sonoma 14.7, though I think this was introduced a few versions ago. Ilya Grigoriev – [Ilya Grigoriev](https://apple.stackexchange.com/users/513181/ilya-grigoriev "270 reputation") 2024-10-02 03:50:40 +00:00 [Commented Oct 2, 2024 at 3:50](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment712191_15484) [Add a comment](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful 4 Save this answer. Show activity on this post. To copy a file to a destination, use the `cp` command. ``` cp /path/to/file /path/to/destination ``` See `man cp` for more information. [Share](https://apple.stackexchange.com/a/15319 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://apple.stackexchange.com/posts/15319/edit) Follow Follow this answer to receive notifications answered Jun 5, 2011 at 8:00 [![Graham's user avatar](https://www.gravatar.com/avatar/1ee4919affc9b134adf1e4b43958ef54?s=64&d=identicon&r=PG)](https://apple.stackexchange.com/users/3158/graham) [Graham](https://apple.stackexchange.com/users/3158/graham) 2,85111 gold badge2020 silver badges1616 bronze badges 2 - 8 This is not an answer to the question asked which references the clipboard as the target location. kellyfj – [kellyfj](https://apple.stackexchange.com/users/57794/kellyfj "101 reputation") 2016-10-26 19:03:44 +00:00 [Commented Oct 26, 2016 at 19:03](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment323615_15319) - @kellyfj I disagree. The subject and the question don't match. It's a terribly worded question. This answers the text in the question body. Quite frankly I can't believe that it got so many upvotes, as far as I'm concerned it should have been closed with "Needs detail or clarity". tink – [tink](https://apple.stackexchange.com/users/178395/tink "326 reputation") 2021-12-14 01:06:41 +00:00 [Commented Dec 14, 2021 at 1:06](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment620138_15319) [Add a comment](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful 2 Save this answer. Show activity on this post. Here's a simple Shell/Bash script. Just paste it in your `.bashrc` file (or the like): ``` file-to-clipboard() { if [ -z "$1" ]; then echo "file path/name:" read FILE else FILE="$1" fi pbcopy < "$FILE" } ``` [Share](https://apple.stackexchange.com/a/123024 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://apple.stackexchange.com/posts/123024/edit) Follow Follow this answer to receive notifications [edited Apr 21, 2017 at 15:12](https://apple.stackexchange.com/posts/123024/revisions "show all edits to this post") answered Mar 4, 2014 at 10:02 [![blizzrdof77's user avatar](https://i.sstatic.net/rBO2v.jpg?s=64)](https://apple.stackexchange.com/users/72016/blizzrdof77) [blizzrdof77](https://apple.stackexchange.com/users/72016/blizzrdof77) 1951010 bronze badges [Add a comment](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful 2 Save this answer. Show activity on this post. Thanks to @Lri and @Chris Johnsen. Another option for you: ``` #!/usr/bin/osascript on run args set abs_path to do shell script "/usr/local/bin/greadlink -f -- " & (first item of args) set the clipboard to POSIX file abs_path end ``` You can put this into a script, and place that script in any folder in your PATH. This combined the idea of using osascript in hashbang and using readlink for relative path. This would achieve the same as @Lri's bash function, but has the advantage of not adding anything to your bashrc. You might need to install readline. You can do so with homebrew ``` brew install readlink ``` [Share](https://apple.stackexchange.com/a/414741 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://apple.stackexchange.com/posts/414741/edit) Follow Follow this answer to receive notifications answered Mar 1, 2021 at 14:23 [![Haodong Du's user avatar](https://www.gravatar.com/avatar/3a100e1fb08c59ee8f9f175d81288498?s=64&d=identicon&r=PG&f=y&so-version=2)](https://apple.stackexchange.com/users/406560/haodong-du) [Haodong Du](https://apple.stackexchange.com/users/406560/haodong-du) 2111 bronze badge 1 - You probably don't need `greadlink` or installing anything these days. [apple.stackexchange.com/questions/15318/…](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard/15484#comment712191_15484 "how to use terminal to copy a file to the clipboard") Ilya Grigoriev – [Ilya Grigoriev](https://apple.stackexchange.com/users/513181/ilya-grigoriev "270 reputation") 2024-10-02 04:04:34 +00:00 [Commented Oct 2, 2024 at 4:04](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment712192_414741) [Add a comment](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful 0 Save this answer. Show activity on this post. With support of relative file: ``` clip_img() { osascript -e 'on run argv' \ -e 'set currentDir to do shell script "pwd"' \ -e 'set the clipboard to (read POSIX file (POSIX path of (currentDir as text & (first item of argv) )) as JPEG picture)' \ -e 'end run' "/$1" # osascript -e 'clipboard info' } ``` run `clip_img path-to-file` to copy image to clipboard, and `path-to-file` could be relative. The file could be jpeg or png files. [Share](https://apple.stackexchange.com/a/359782 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://apple.stackexchange.com/posts/359782/edit) Follow Follow this answer to receive notifications answered May 10, 2019 at 4:44 [![schemacs's user avatar](https://www.gravatar.com/avatar/8a0d717f7a131eb4c9ba588f99716aa0?s=64&d=identicon&r=PG)](https://apple.stackexchange.com/users/116120/schemacs) [schemacs](https://apple.stackexchange.com/users/116120/schemacs) 10333 bronze badges [Add a comment](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful 0 Save this answer. Show activity on this post. I'm only 11 years late but I think I have an alternative, albeit, hacky solution. Here's my script: ``` #!/usr/bin/env bash fzf -m -e | xargs -n1 open -R osascript -e 'tell application "System Events" to keystroke "c" using command down' osascript -e 'tell application "System Events" to keystroke "w" using command down' open -a "Slack.app" osascript -e 'tell application "System Events" to keystroke "v" using command down' osascript -e 'tell application "System Events" to key code 76' exit 0 ``` A few disclaimers: - This assumes a macOS environment. - In the script, I'm using a command line tool called `fzf` which is not needed. It just makes searching for things easier. You can get it from `brew install fzf` if you're interested. - My use case was to find a way to search, find and send gifs quickly in Slack. So I named it 'fzygif'. ![fzygif.png](https://www.dropbox.com/s/7fy3xegp1abapso/fzygif.png?dl=1) *(The following description references the line numbers in the image above:)* - Line no. 3 - `fzf -m -e` is to allow for multiple files to be selected as well as to search using the exact term used. The result is then piped into `xargs -n1 open -R` which then applies the `open` command to each search result, one at a time. - Line no. 5 - Next I use the `osascript -e` command to simulate `Cmd`\+`C` which is the Apple keyboard shortcut for **Copy**. - Line no. 7 - Next I use the `osascript -e` command to simulate `Cmd`\+`W` which is the Apple keyboard shortcut for **Close Window** (just doing a little housekeeping along the way; this could be omitted). - Line no. 9 - Next I open Slack (the intended target for my recently copied gif; open whatever app tickles you). - Line no. 11 - Next I use the `osascript -e` command to simulate `Cmd`\+`V` which is the Apple keyboard shortcut for **Paste**. - Line no. 13 - Lastly, I use the `osascript -e` command to simulate "key code 76" which is the Apple key code for `Enter`. This is to automatically send the gif in Slack after it's pasted (this too could be omitted). Since a gif is worth a thousand words? Here it is in action: ![copy-gif-to-clipboard.gif](https://www.dropbox.com/s/wfkwve6bw6sp0rq/copy-gif-to-clipboard.gif?dl=1) Happy hacking\! [Share](https://apple.stackexchange.com/a/450858 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://apple.stackexchange.com/posts/450858/edit) Follow Follow this answer to receive notifications [edited Feb 9, 2023 at 15:59](https://apple.stackexchange.com/posts/450858/revisions "show all edits to this post") [![agarza's user avatar](https://lh4.googleusercontent.com/-a00ebwHoqnU/AAAAAAAAAAI/AAAAAAAABh0/AMZuucmX_xwLf8iD5MppVm9OaKT_7zMSig/s64-rj/photo.jpg)](https://apple.stackexchange.com/users/381466/agarza) [agarza](https://apple.stackexchange.com/users/381466/agarza) 2,41788 gold badges1919 silver badges2929 bronze badges answered Nov 21, 2022 at 3:53 [![Zaphod Beeblebrox's user avatar](https://i.sstatic.net/5o4Ft.jpg?s=64)](https://apple.stackexchange.com/users/435282/zaphod-beeblebrox) [Zaphod Beeblebrox](https://apple.stackexchange.com/users/435282/zaphod-beeblebrox) 933 bronze badges [Add a comment](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful \-2 Save this answer. Show activity on this post. You can use cat 'originfile' \> 'destinationfile' on unix environments; copy originfile destinationfile on windows. [Share](https://apple.stackexchange.com/a/311433 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://apple.stackexchange.com/posts/311433/edit) Follow Follow this answer to receive notifications answered Jan 6, 2018 at 21:06 [![Allan Felipe Murara's user avatar](https://graph.facebook.com/945869572097724/picture?type=large)](https://apple.stackexchange.com/users/271003/allan-felipe-murara) [Allan Felipe Murara](https://apple.stackexchange.com/users/271003/allan-felipe-murara) 10111 bronze badge 1 - 2 How does this place the file on the clipboard? grg – [grg](https://apple.stackexchange.com/users/37797/grg "208,925 reputation") ♦ 2018-01-06 22:27:22 +00:00 [Commented Jan 6, 2018 at 22:27](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard#comment394983_311433) [Add a comment](https://apple.stackexchange.com/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| ## You must [log in](https://apple.stackexchange.com/users/login?ssrc=question_page&returnurl=https%3A%2F%2Fapple.stackexchange.com%2Fquestions%2F15318) to answer this question. **[Protected question](https://apple.stackexchange.com/help/privileges/protect-questions)**. To answer this question, you need to have at least 10 reputation on this site (not counting the [association bonus](https://meta.stackexchange.com/questions/141648/what-is-the-association-bonus-and-how-does-it-work)). The reputation requirement helps protect this question from spam and non-answer activity. Start asking to get answers Find the answer to your question by asking. [Ask question](https://apple.stackexchange.com/questions/ask) Explore related questions - [mac](https://apple.stackexchange.com/questions/tagged/mac "show questions tagged 'mac'") - [terminal](https://apple.stackexchange.com/questions/tagged/terminal "show questions tagged 'terminal'") See similar questions with these tags. #### Linked [1](https://apple.stackexchange.com/questions/473364/copy-file-from-terminal-into-clipboard-and-paste-in-finder?lq=1 "Question score (upvotes - downvotes)") [Copy file from terminal into clipboard and paste in Finder](https://apple.stackexchange.com/questions/473364/copy-file-from-terminal-into-clipboard-and-paste-in-finder?noredirect=1&lq=1) [4](https://apple.stackexchange.com/questions/475926/access-clipboard-contents-from-the-command-line?lq=1 "Question score (upvotes - downvotes)") [Access clipboard contents from the command line](https://apple.stackexchange.com/questions/475926/access-clipboard-contents-from-the-command-line?noredirect=1&lq=1) [1](https://apple.stackexchange.com/questions/362245/copy-file-from-terminal-and-paste-in-mail?lq=1 "Question score (upvotes - downvotes)") [Copy file from Terminal and paste in Mail](https://apple.stackexchange.com/questions/362245/copy-file-from-terminal-and-paste-in-mail?noredirect=1&lq=1) [1](https://apple.stackexchange.com/questions/436969/triggering-a-paste-from-the-command-line?lq=1 "Question score (upvotes - downvotes)") [Triggering a paste from the command line](https://apple.stackexchange.com/questions/436969/triggering-a-paste-from-the-command-line?noredirect=1&lq=1) #### Related [1](https://apple.stackexchange.com/questions/32316/how-to-have-clipboard-holding-many-entries-available-simultaneously?rq=1 "Question score (upvotes - downvotes)") [How to have clipboard holding many entries available simultaneously...?](https://apple.stackexchange.com/questions/32316/how-to-have-clipboard-holding-many-entries-available-simultaneously?rq=1) [8](https://apple.stackexchange.com/questions/93041/terminal-search-files-by-text-that-the-file-names-contain?rq=1 "Question score (upvotes - downvotes)") [terminal search files by text that the file names contain](https://apple.stackexchange.com/questions/93041/terminal-search-files-by-text-that-the-file-names-contain?rq=1) [30](https://apple.stackexchange.com/questions/110343/copy-last-command-in-terminal?rq=1 "Question score (upvotes - downvotes)") [copy last command in terminal](https://apple.stackexchange.com/questions/110343/copy-last-command-in-terminal?rq=1) [0](https://apple.stackexchange.com/questions/213087/copy-a-file-to-the-root-directory?rq=1 "Question score (upvotes - downvotes)") [Copy a file to the root directory](https://apple.stackexchange.com/questions/213087/copy-a-file-to-the-root-directory?rq=1) [0](https://apple.stackexchange.com/questions/230757/how-to-copy-a-file-and-replace-if-necessary-in-the-target-directory-from-termi?rq=1 "Question score (upvotes - downvotes)") [How to copy a file and replace (if necessary) in the target directory from terminal](https://apple.stackexchange.com/questions/230757/how-to-copy-a-file-and-replace-if-necessary-in-the-target-directory-from-termi?rq=1) [6](https://apple.stackexchange.com/questions/336228/make-ctrl-k-in-terminal-copy-to-the-system-clipboard?rq=1 "Question score (upvotes - downvotes)") [Make Ctrl-k in Terminal copy to the system clipboard](https://apple.stackexchange.com/questions/336228/make-ctrl-k-in-terminal-copy-to-the-system-clipboard?rq=1) [2](https://apple.stackexchange.com/questions/422307/the-open-folder-command-in-terminal-and-the-reveal-file-in-finder-option-a?rq=1 "Question score (upvotes - downvotes)") [The 'open \<folder\>' command in Terminal and the 'Reveal file in Finder' option aren't working](https://apple.stackexchange.com/questions/422307/the-open-folder-command-in-terminal-and-the-reveal-file-in-finder-option-a?rq=1) [0](https://apple.stackexchange.com/questions/457905/using-terminal-how-to-copy-paste-a-folder-like-you-would-from-finder?rq=1 "Question score (upvotes - downvotes)") [Using terminal, how to copy paste a folder, like you would from finder?](https://apple.stackexchange.com/questions/457905/using-terminal-how-to-copy-paste-a-folder-like-you-would-from-finder?rq=1) #### [Hot Network Questions](https://stackexchange.com/questions?tab=hot) - [Do those who later identify as “ex-Christians” remain saved under the “once saved, always saved” doctrine?](https://christianity.stackexchange.com/questions/113496/do-those-who-later-identify-as-ex-christians-remain-saved-under-the-once-save) - [Stage-One Bootloader](https://codereview.stackexchange.com/questions/301718/stage-one-bootloader) - [How to make manpages sans-serif?](https://unix.stackexchange.com/questions/805212/how-to-make-manpages-sans-serif) - [What is the difference between a tautology and a definition?](https://philosophy.stackexchange.com/questions/137369/what-is-the-difference-between-a-tautology-and-a-definition) - [Why do larger language models still fail on simple compositional reasoning tasks?](https://ai.stackexchange.com/questions/50497/why-do-larger-language-models-still-fail-on-simple-compositional-reasoning-tasks) - [Evolution vs is ought arguments?](https://philosophy.stackexchange.com/questions/137382/evolution-vs-is-ought-arguments) - [Graph of f and f' with luacas package](https://tex.stackexchange.com/questions/761450/graph-of-f-and-f-with-luacas-package) - [Why do the rules of senate appointment seem so inconsistent?](https://politics.stackexchange.com/questions/94476/why-do-the-rules-of-senate-appointment-seem-so-inconsistent) - [Which files can an LLM agent access, and how are these restrictions enforced?](https://genai.stackexchange.com/questions/2729/which-files-can-an-llm-agent-access-and-how-are-these-restrictions-enforced) - [Must TLS v1.3 server send intermediate certificate or not during a handshake?](https://crypto.stackexchange.com/questions/119484/must-tls-v1-3-server-send-intermediate-certificate-or-not-during-a-handshake) - [80s–2000s movie—club bar scene where a couple signs a contract to hook up and they set the dos and don'ts](https://movies.stackexchange.com/questions/131642/80s-2000s-movie-club-bar-scene-where-a-couple-signs-a-contract-to-hook-up-and-th) - [Highest die in a standard dice pool after eliminating dice vs a rerolling, exploding, dice pool](https://rpg.stackexchange.com/questions/219029/highest-die-in-a-standard-dice-pool-after-eliminating-dice-vs-a-rerolling-explo) - [Parent push bike where the pedals move WITH the wheels](https://bicycles.stackexchange.com/questions/100129/parent-push-bike-where-the-pedals-move-with-the-wheels) - [Will updating Ubuntu break my Wine installation?](https://askubuntu.com/questions/1565307/will-updating-ubuntu-break-my-wine-installation) - [Does “Ur of the Chaldeans” imply Abraham was Babylonian or Mesopotamian?](https://hermeneutics.stackexchange.com/questions/115596/does-ur-of-the-chaldeans-imply-abraham-was-babylonian-or-mesopotamian) - [For purposes of administration of the estate of a decedent, what counts as a funeral?](https://law.stackexchange.com/questions/114483/for-purposes-of-administration-of-the-estate-of-a-decedent-what-counts-as-a-fun) - [Projective resolutions in the wrong direction](https://math.stackexchange.com/questions/5131032/projective-resolutions-in-the-wrong-direction) - [Can I punch an astral entity while using Astral Perception](https://rpg.stackexchange.com/questions/219036/can-i-punch-an-astral-entity-while-using-astral-perception) - [My vinyls have all caught colds\!](https://codegolf.stackexchange.com/questions/287712/my-vinyls-have-all-caught-colds) - [mgt.clearMarks is not a function](https://stackoverflow.com/questions/79917862/mgt-clearmarks-is-not-a-function) - [Alternative proof of the Riesz Representation Theorem](https://math.stackexchange.com/questions/5130822/alternative-proof-of-the-riesz-representation-theorem) - [Short story from the 1930’s through mid 1950’s with a plot that includes robots learning how to replicate independently of humans?](https://scifi.stackexchange.com/questions/303864/short-story-from-the-1930-s-through-mid-1950-s-with-a-plot-that-includes-robots) - [Movement of space vehicles](https://space.stackexchange.com/questions/70381/movement-of-space-vehicles) - [Does On-Chip Decoupling Negate the Need for PCB PDN Analysis](https://electronics.stackexchange.com/questions/767597/does-on-chip-decoupling-negate-the-need-for-pcb-pdn-analysis) [Question feed](https://apple.stackexchange.com/feeds/question/15318 "Feed of this question and its answers") # Subscribe to RSS Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader. ![](https://apple.stackexchange.com/posts/15318/ivc/b54b?prg=09b948ac-68d1-422c-a1d6-9ab072b2a7f6) lang-bash # Why are you flagging this comment? It contains harassment, bigotry or abuse. This comment attacks a person or group. Learn more in our [Abusive behavior policy](https://apple.stackexchange.com/conduct/abusive-behavior). It's unfriendly or unkind. This comment is rude or condescending. Learn more in our [Code of Conduct](https://apple.stackexchange.com/conduct/abusive-behavior). Not needed. This comment is not relevant to the post. ``` ``` Enter at least 6 characters Something else. A problem not listed above. Try to be as specific as possible. ``` ``` Enter at least 6 characters Flag comment Cancel You have 0 flags left today # ![Illustration of upvote icon after it is clicked](https://apple.stackexchange.com/Content/Img/modal/img-upvote.png?v=fce73bd9724d) # Hang on, you can't upvote just yet. You'll need to complete a few actions and gain 15 reputation points before being able to upvote. **Upvoting** indicates when questions and answers are useful. [What's reputation and how do I get it?](https://stackoverflow.com/help/whats-reputation) Instead, you can save this post to reference later. Save this post for later Not now ##### [Ask Different](https://apple.stackexchange.com/) - [Tour](https://apple.stackexchange.com/tour) - [Help](https://apple.stackexchange.com/help) - [Chat](https://chat.stackexchange.com/?tab=site&host=apple.stackexchange.com) - [Contact](https://apple.stackexchange.com/contact) - [Feedback](https://apple.meta.stackexchange.com/) ##### [Company](https://stackoverflow.co/) - [Stack Overflow](https://stackoverflow.com/) - [Stack Internal](https://stackoverflow.co/internal/) - [Stack Data Licensing](https://stackoverflow.co/data-licensing/) - [Stack Ads](https://stackoverflow.co/advertising/) - [About](https://stackoverflow.co/) - [Press](https://stackoverflow.co/company/press/) - [Legal](https://stackoverflow.com/legal) - [Privacy Policy](https://stackoverflow.com/legal/privacy-policy) - [Terms of Service](https://stackoverflow.com/legal/terms-of-service/public) - Cookie Settings - [Cookie Policy](https://policies.stackoverflow.co/stack-overflow/cookie-policy) ##### [Stack Exchange Network](https://stackexchange.com/) - [Technology](https://stackexchange.com/sites#technology) - [Culture & recreation](https://stackexchange.com/sites#culturerecreation) - [Life & arts](https://stackexchange.com/sites#lifearts) - [Science](https://stackexchange.com/sites#science) - [Professional](https://stackexchange.com/sites#professional) - [Business](https://stackexchange.com/sites#business) - [API](https://api.stackexchange.com/) - [Data](https://data.stackexchange.com/) - [Blog](https://stackoverflow.blog/?blb=1) - [Facebook](https://www.facebook.com/officialstackoverflow/) - [Twitter](https://twitter.com/stackoverflow) - [LinkedIn](https://linkedin.com/company/stack-overflow) - [Instagram](https://www.instagram.com/thestackoverflow) Site design / logo © 2026 Stack Exchange Inc; user contributions licensed under [CC BY-SA](https://stackoverflow.com/help/licensing) . rev 2026.3.27.41560 Apple is a trademark of Apple Inc., registered in the US and other countries. This site is not affiliated with or endorsed by Apple Inc. in any way.
Readable Markdown
There is no way to achieve what you are trying to do using the command line. While Apple offers the `pbcopy` and `pbpaste` tools to allow basic copying of text, you cannot use these tools to copy a file in the sense you're looking for. Without going in to too much technical detail, when you 'copy' a file in the Finder using `⌘``C`, you're not actually copying the file itself, just making a reference to the file on the clipboard and marking it as a file reference. When an application receives this reference when you paste, it has the responsibility of sorting things out, figuring out what you pasted, and ultimately, working with the file as it sees fit. In essence, when you copy a file in the Finder, it saves the path to the file in a certain way to a certain clipboard, and when you paste, it receives that file path and knows to create a new file using the contents of the old one (copy a file to the clipboard, delete it, try to paste it somewhere else, and see what happens, for instance). In this sense of copying and pasting, the tools available at hand are not enough to do what you need. As boehj suggested, you can try to copy the contents of the old file into a new one, but this will only work well for text files. Any binary files you get will be corrupted (try doing this with an image – it becomes corrupted). The traditional command line will fail you in this way, but you can take a look if you'd like into doing this in AppleScript, then invoking that through the command line with `osascript`.
Shard18 (laksa)
Root Hash8045678284012640218
Unparsed URLcom,stackexchange!apple,/questions/15318/how-to-use-terminal-to-copy-a-file-to-the-clipboard s443