Clipboard for copying and pasting files in command line?












24














In Bash, suppose I visit a directory, and then another directory. I would like to copy a file from the first directory to the second directory, but without specifying the long pathnames of them. Is it possible?



My temporary solution is to use /tmp as a temporary place to store a copy of the file. cp myfile /tmp when I am in the first directory, and then cp /tmp/myfile . when I am in the second directory. But I may check if the file will overwrite anything in /tmp.



Is there something similar to a clipboard for copying and pasting a file?










share|improve this question




















  • 1




    You have to type the cd command, so you can just cd - to go back to the previous directory, up-arrow to recall the cd command, and edit the line to be cp instead of cd. (ctrl-a(beginning-of-line), alt-d (kill-word), cp -a, ctrl-e(end-of-line)).
    – Peter Cordes
    Mar 10 '16 at 15:40










  • With Emacs and M-x term you can use Emacs' clipboard.
    – Pål GD
    Mar 10 '16 at 17:56






  • 1




    You can use Midnight Commander and forget about jumping through the hoops.
    – Deer Hunter
    Mar 10 '16 at 19:29










  • @PålGD People say Emacs' is an operating system... Most have clipboards ;)
    – Volker Siegel
    Mar 13 '16 at 11:18










  • @JeffSchaller thanks................................
    – Tim
    May 13 '17 at 14:58
















24














In Bash, suppose I visit a directory, and then another directory. I would like to copy a file from the first directory to the second directory, but without specifying the long pathnames of them. Is it possible?



My temporary solution is to use /tmp as a temporary place to store a copy of the file. cp myfile /tmp when I am in the first directory, and then cp /tmp/myfile . when I am in the second directory. But I may check if the file will overwrite anything in /tmp.



Is there something similar to a clipboard for copying and pasting a file?










share|improve this question




















  • 1




    You have to type the cd command, so you can just cd - to go back to the previous directory, up-arrow to recall the cd command, and edit the line to be cp instead of cd. (ctrl-a(beginning-of-line), alt-d (kill-word), cp -a, ctrl-e(end-of-line)).
    – Peter Cordes
    Mar 10 '16 at 15:40










  • With Emacs and M-x term you can use Emacs' clipboard.
    – Pål GD
    Mar 10 '16 at 17:56






  • 1




    You can use Midnight Commander and forget about jumping through the hoops.
    – Deer Hunter
    Mar 10 '16 at 19:29










  • @PålGD People say Emacs' is an operating system... Most have clipboards ;)
    – Volker Siegel
    Mar 13 '16 at 11:18










  • @JeffSchaller thanks................................
    – Tim
    May 13 '17 at 14:58














24












24








24


14





In Bash, suppose I visit a directory, and then another directory. I would like to copy a file from the first directory to the second directory, but without specifying the long pathnames of them. Is it possible?



My temporary solution is to use /tmp as a temporary place to store a copy of the file. cp myfile /tmp when I am in the first directory, and then cp /tmp/myfile . when I am in the second directory. But I may check if the file will overwrite anything in /tmp.



Is there something similar to a clipboard for copying and pasting a file?










share|improve this question















In Bash, suppose I visit a directory, and then another directory. I would like to copy a file from the first directory to the second directory, but without specifying the long pathnames of them. Is it possible?



My temporary solution is to use /tmp as a temporary place to store a copy of the file. cp myfile /tmp when I am in the first directory, and then cp /tmp/myfile . when I am in the second directory. But I may check if the file will overwrite anything in /tmp.



Is there something similar to a clipboard for copying and pasting a file?







bash command-line directory filenames command-history






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 10 '16 at 22:17









Gilles

528k12810571583




528k12810571583










asked Mar 10 '16 at 3:58









Tim

25.9k74246454




25.9k74246454








  • 1




    You have to type the cd command, so you can just cd - to go back to the previous directory, up-arrow to recall the cd command, and edit the line to be cp instead of cd. (ctrl-a(beginning-of-line), alt-d (kill-word), cp -a, ctrl-e(end-of-line)).
    – Peter Cordes
    Mar 10 '16 at 15:40










  • With Emacs and M-x term you can use Emacs' clipboard.
    – Pål GD
    Mar 10 '16 at 17:56






  • 1




    You can use Midnight Commander and forget about jumping through the hoops.
    – Deer Hunter
    Mar 10 '16 at 19:29










  • @PålGD People say Emacs' is an operating system... Most have clipboards ;)
    – Volker Siegel
    Mar 13 '16 at 11:18










  • @JeffSchaller thanks................................
    – Tim
    May 13 '17 at 14:58














  • 1




    You have to type the cd command, so you can just cd - to go back to the previous directory, up-arrow to recall the cd command, and edit the line to be cp instead of cd. (ctrl-a(beginning-of-line), alt-d (kill-word), cp -a, ctrl-e(end-of-line)).
    – Peter Cordes
    Mar 10 '16 at 15:40










  • With Emacs and M-x term you can use Emacs' clipboard.
    – Pål GD
    Mar 10 '16 at 17:56






  • 1




    You can use Midnight Commander and forget about jumping through the hoops.
    – Deer Hunter
    Mar 10 '16 at 19:29










  • @PålGD People say Emacs' is an operating system... Most have clipboards ;)
    – Volker Siegel
    Mar 13 '16 at 11:18










  • @JeffSchaller thanks................................
    – Tim
    May 13 '17 at 14:58








1




1




You have to type the cd command, so you can just cd - to go back to the previous directory, up-arrow to recall the cd command, and edit the line to be cp instead of cd. (ctrl-a(beginning-of-line), alt-d (kill-word), cp -a, ctrl-e(end-of-line)).
– Peter Cordes
Mar 10 '16 at 15:40




You have to type the cd command, so you can just cd - to go back to the previous directory, up-arrow to recall the cd command, and edit the line to be cp instead of cd. (ctrl-a(beginning-of-line), alt-d (kill-word), cp -a, ctrl-e(end-of-line)).
– Peter Cordes
Mar 10 '16 at 15:40












With Emacs and M-x term you can use Emacs' clipboard.
– Pål GD
Mar 10 '16 at 17:56




With Emacs and M-x term you can use Emacs' clipboard.
– Pål GD
Mar 10 '16 at 17:56




1




1




You can use Midnight Commander and forget about jumping through the hoops.
– Deer Hunter
Mar 10 '16 at 19:29




You can use Midnight Commander and forget about jumping through the hoops.
– Deer Hunter
Mar 10 '16 at 19:29












@PålGD People say Emacs' is an operating system... Most have clipboards ;)
– Volker Siegel
Mar 13 '16 at 11:18




@PålGD People say Emacs' is an operating system... Most have clipboards ;)
– Volker Siegel
Mar 13 '16 at 11:18












@JeffSchaller thanks................................
– Tim
May 13 '17 at 14:58




@JeffSchaller thanks................................
– Tim
May 13 '17 at 14:58










8 Answers
8






active

oldest

votes


















57














Using Bash, I would just visit the directories:



$ cd /path/to/source/directory
$ cd /path/to/destination/directory


Then, I would use the shortcut ~-, which points to the previous directory:



$ cp -v ~-/file1.txt .
$ cp -v ~-/file2.txt .
$ cp -v ~-/file3.txt .




If one wants to visit directories in reverse order, then:



$ cp -v fileA.txt ~-
$ cp -v fileB.txt ~-
$ cp -v fileC.txt ~-





share|improve this answer

















  • 25




    +1 I'm using Unix/Linux shells for more than 20 years now, and I didnt' know that shortcut.
    – Dubu
    Mar 10 '16 at 11:30






  • 4




    Huh, that is a handy shortcut for "$OLDPWD". Why three separate cp commands, though? cp -a ~-/file[1-3].txt .
    – Peter Cordes
    Mar 10 '16 at 15:32






  • 4




    Actually, the three cp's are examples. In the real world, wildcard characters can also be used to simplify the copy task.
    – Anderson M. Gomes
    Mar 10 '16 at 16:39






  • 2




    I was going to mention something about pushd and parsing dirs...but this is far, far better. I suggest you add the fact that "$OLDPWD" is exactly equivalent to ~- and is more portable (helpful for those not using bash.)
    – Wildcard
    Mar 11 '16 at 5:54






  • 1




    ~+ is likewise a shortcut for "$PWD"
    – Paul Evans
    Mar 12 '16 at 21:23



















10














If I saw that situation coming as a one-off, I might:



a=`pwd`
cd /somewhere/else
cp "$a/myfile" .


If there were directories that I found myself copying files out of semi-regularly, I would probably define some mnemonic variables for them in my .profile.



Edited to add:



After sleeping on it, I wondered how closely I could get to other GUI / OS behaviors where you select some number of files, "cut" or "copy" them, then "paste" them somewhere else. The best selection mechanism I could come up with was your brain/preferences plus the shell's globbing feature. I'm not very creative with naming, but this is the basic idea (in Bash syntax):



function copyfiles {
_copypastefiles=("$@")
_copypastesrc="$PWD"
_copypastemode=copy
}

function cutfiles {
_copypastefiles=("$@")
_copypastesrc="$PWD"
_copypastemode=cut
}

function pastefiles {
for f in "${_copypastefiles[@]}"
do
cp "${_copypastesrc}/$f" .
if [[ ${_copypastemode} = "cut" ]]
then
rm "${_copypastesrc}/$f"
fi
done
}


To use it, put the code into ~/.bash_profile, then cd to the source directory and run either copyfiles glob*here or cutfiles glob*here. All that happens is that your shell expands the globs and puts those filenames into an array. You then cd to the destination directory and run pastefiles, which executes a cp command for each source file. If you had previously "cut" the files, then pastefiles also removes the source file (or, tries to). This doesn't do any error-checking (of existing files, before potentially clobbering them with the cp; or that you have permissions to remove the files during a "cut", or that you can re-access the source directory after you move out of it).






share|improve this answer



















  • 3




    For your one-off, $OLDPWD already exists, which can be shortened to ~- in bash and zsh.
    – Gilles
    Mar 10 '16 at 19:50





















5














I think the ~- is the right answer, but note that bash has a built-in line editor that can copy/paste text.



If you are in emacs mode you can recall your cd command from the history, and use Control-u to kill the line into the bash "clipboard" called the kill-ring (there are other ways too). You can then yank this string into a new command at any time with Control-y. Obviously, in your example this depends on you having used an absolute directory name in your cd command.



You can also use the interesting default key-binding of Meta-.. This copies the last word from the previous command into your current line. If repeated, each time it goes back one command in the history. So if you do a cd /x, then cd /y followed by cdMeta-.Meta-. you will have /x in your input.






share|improve this answer





























    5














    Expanding on the answer from Anderson M. Gomes, Bash allows you to refer to any prior directory in your directory stack by typing ~N (or ~+N) where N is the position on the dir stack. For example:



    # go some places
    $ cd /path/to/source/directory
    $ pushd /path/to/destination/directory
    $ pushd $HOME
    $ pushd /tmp

    # show the current dir stack
    $ dirs -v
    0 /tmp
    1 ~
    2 /path/to/destination/directory
    3 /path/to/source/directory


    Now you can copy a file between two past directories, neither of them the current one, with:



    cp -v ~3/file1.txt ~2




    To solve the original poster's problem, you would do:



    $ cd /path/to/source/directory
    $ pushd /path/to/destination/directory

    # show the current dir stack
    $ dirs -v
    0 /path/to/destination/directory
    1 /path/to/source/directory

    # copy
    cp -v ~1/file[123].txt .


    With a large set of files, you could list their names in a manifest file and then do the copy from the source dir:



    $ cd /path/to/destination/directory
    $ pushd /path/to/source/directory

    # copy
    cp -v $(cat files_to_copy.list) ~1


    See also: this section of the Bash man page





    Similarly, in Tcsh, you can use the =2 notation (rather than ~2) to refer to the second dir on your dir stack.



    See also: this section of the Tcsh man page






    share|improve this answer































      4














      when you are in the first directory, lets say the source or src in short, execute



      src=${PWD}


      then cd in to second directory and execute:



      cp -i ${src}/filename .


      the -i option will ask if you want to overwrite, if there is a duplicate file






      share|improve this answer





















      • Thanks. It is even better without specifying the filename.
        – Tim
        Mar 10 '16 at 4:14



















      4














      A variation on anderson-m-gomes response.
      Using Bash, I would just visit the directories:



      $ cd /path/to/source/directory
      $ cd /path/to/destination/directory


      Then, I would use the variable $OLDPWD, which points to the previous directory:



      $ cp -v $OLDPWD/file1.txt .


      If one wants to visit directories in reverse order, then:



      $ cp -v fileA.txt $OLDPWD/





      share|improve this answer

















      • 3




        +1, but you forgot to "quote" your variable expansions. If $OLDPWD contains spaces, this breaks. Also, I always use cp -a. Also, it's unfortunate that tab-completion is broken on variable expansions. You can use ctrl-alt-e to shell-expand the current command line, though, after typing the $OLDPWD part.
        – Peter Cordes
        Mar 10 '16 at 15:30






      • 1




        ~- is a shortcut for $OLDPWD
        – Gilles
        Mar 10 '16 at 19:51










      • I was just pointing out another variation, since Unix/Linux is full of them. Funny, that I've been using Linux for >20 years, and I'd never seen ~- before. Plus, $OLDPWD is easy to remember.
        – Scott Carlson
        Mar 14 '16 at 17:54



















      3














      If in bash, I would use pushd and popd. These commands keep a handy FIFO stack of directories for later use. You can consult the stack anytime using dirs.



      As such I would do:



      pushd .
      cd /somewhere/else
      cp "`popd`/myfile"





      share|improve this answer































        2














        You can use xclip:



        NAME
        xclip - command line interface to X selections (clipboard)

        SYNOPSIS
        xclip [OPTION] [FILE]...

        DESCRIPTION
        Reads from standard in, or from one or more files, and makes the data available as an X selection for pasting
        into X applications. Prints current X selection to standard out.


        Example:



        $ cd /path/to/dir1
        $ xclip-copyfile file1 file2
        $ cd /path/to/dir2
        $ xclip-pastefile
        file1 file2


        Also visit xsel.






        share|improve this answer























        • That does a tar | gzip into / out of the X clipboard. Kinda clunky compared to cp, and doesn't generalize to making symlinks or hardlinks. (cp -as or cp -al)
          – Peter Cordes
          Mar 10 '16 at 15:44











        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "106"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f268818%2fclipboard-for-copying-and-pasting-files-in-command-line%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        8 Answers
        8






        active

        oldest

        votes








        8 Answers
        8






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        57














        Using Bash, I would just visit the directories:



        $ cd /path/to/source/directory
        $ cd /path/to/destination/directory


        Then, I would use the shortcut ~-, which points to the previous directory:



        $ cp -v ~-/file1.txt .
        $ cp -v ~-/file2.txt .
        $ cp -v ~-/file3.txt .




        If one wants to visit directories in reverse order, then:



        $ cp -v fileA.txt ~-
        $ cp -v fileB.txt ~-
        $ cp -v fileC.txt ~-





        share|improve this answer

















        • 25




          +1 I'm using Unix/Linux shells for more than 20 years now, and I didnt' know that shortcut.
          – Dubu
          Mar 10 '16 at 11:30






        • 4




          Huh, that is a handy shortcut for "$OLDPWD". Why three separate cp commands, though? cp -a ~-/file[1-3].txt .
          – Peter Cordes
          Mar 10 '16 at 15:32






        • 4




          Actually, the three cp's are examples. In the real world, wildcard characters can also be used to simplify the copy task.
          – Anderson M. Gomes
          Mar 10 '16 at 16:39






        • 2




          I was going to mention something about pushd and parsing dirs...but this is far, far better. I suggest you add the fact that "$OLDPWD" is exactly equivalent to ~- and is more portable (helpful for those not using bash.)
          – Wildcard
          Mar 11 '16 at 5:54






        • 1




          ~+ is likewise a shortcut for "$PWD"
          – Paul Evans
          Mar 12 '16 at 21:23
















        57














        Using Bash, I would just visit the directories:



        $ cd /path/to/source/directory
        $ cd /path/to/destination/directory


        Then, I would use the shortcut ~-, which points to the previous directory:



        $ cp -v ~-/file1.txt .
        $ cp -v ~-/file2.txt .
        $ cp -v ~-/file3.txt .




        If one wants to visit directories in reverse order, then:



        $ cp -v fileA.txt ~-
        $ cp -v fileB.txt ~-
        $ cp -v fileC.txt ~-





        share|improve this answer

















        • 25




          +1 I'm using Unix/Linux shells for more than 20 years now, and I didnt' know that shortcut.
          – Dubu
          Mar 10 '16 at 11:30






        • 4




          Huh, that is a handy shortcut for "$OLDPWD". Why three separate cp commands, though? cp -a ~-/file[1-3].txt .
          – Peter Cordes
          Mar 10 '16 at 15:32






        • 4




          Actually, the three cp's are examples. In the real world, wildcard characters can also be used to simplify the copy task.
          – Anderson M. Gomes
          Mar 10 '16 at 16:39






        • 2




          I was going to mention something about pushd and parsing dirs...but this is far, far better. I suggest you add the fact that "$OLDPWD" is exactly equivalent to ~- and is more portable (helpful for those not using bash.)
          – Wildcard
          Mar 11 '16 at 5:54






        • 1




          ~+ is likewise a shortcut for "$PWD"
          – Paul Evans
          Mar 12 '16 at 21:23














        57












        57








        57






        Using Bash, I would just visit the directories:



        $ cd /path/to/source/directory
        $ cd /path/to/destination/directory


        Then, I would use the shortcut ~-, which points to the previous directory:



        $ cp -v ~-/file1.txt .
        $ cp -v ~-/file2.txt .
        $ cp -v ~-/file3.txt .




        If one wants to visit directories in reverse order, then:



        $ cp -v fileA.txt ~-
        $ cp -v fileB.txt ~-
        $ cp -v fileC.txt ~-





        share|improve this answer












        Using Bash, I would just visit the directories:



        $ cd /path/to/source/directory
        $ cd /path/to/destination/directory


        Then, I would use the shortcut ~-, which points to the previous directory:



        $ cp -v ~-/file1.txt .
        $ cp -v ~-/file2.txt .
        $ cp -v ~-/file3.txt .




        If one wants to visit directories in reverse order, then:



        $ cp -v fileA.txt ~-
        $ cp -v fileB.txt ~-
        $ cp -v fileC.txt ~-






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 10 '16 at 5:17









        Anderson M. Gomes

        1,05647




        1,05647








        • 25




          +1 I'm using Unix/Linux shells for more than 20 years now, and I didnt' know that shortcut.
          – Dubu
          Mar 10 '16 at 11:30






        • 4




          Huh, that is a handy shortcut for "$OLDPWD". Why three separate cp commands, though? cp -a ~-/file[1-3].txt .
          – Peter Cordes
          Mar 10 '16 at 15:32






        • 4




          Actually, the three cp's are examples. In the real world, wildcard characters can also be used to simplify the copy task.
          – Anderson M. Gomes
          Mar 10 '16 at 16:39






        • 2




          I was going to mention something about pushd and parsing dirs...but this is far, far better. I suggest you add the fact that "$OLDPWD" is exactly equivalent to ~- and is more portable (helpful for those not using bash.)
          – Wildcard
          Mar 11 '16 at 5:54






        • 1




          ~+ is likewise a shortcut for "$PWD"
          – Paul Evans
          Mar 12 '16 at 21:23














        • 25




          +1 I'm using Unix/Linux shells for more than 20 years now, and I didnt' know that shortcut.
          – Dubu
          Mar 10 '16 at 11:30






        • 4




          Huh, that is a handy shortcut for "$OLDPWD". Why three separate cp commands, though? cp -a ~-/file[1-3].txt .
          – Peter Cordes
          Mar 10 '16 at 15:32






        • 4




          Actually, the three cp's are examples. In the real world, wildcard characters can also be used to simplify the copy task.
          – Anderson M. Gomes
          Mar 10 '16 at 16:39






        • 2




          I was going to mention something about pushd and parsing dirs...but this is far, far better. I suggest you add the fact that "$OLDPWD" is exactly equivalent to ~- and is more portable (helpful for those not using bash.)
          – Wildcard
          Mar 11 '16 at 5:54






        • 1




          ~+ is likewise a shortcut for "$PWD"
          – Paul Evans
          Mar 12 '16 at 21:23








        25




        25




        +1 I'm using Unix/Linux shells for more than 20 years now, and I didnt' know that shortcut.
        – Dubu
        Mar 10 '16 at 11:30




        +1 I'm using Unix/Linux shells for more than 20 years now, and I didnt' know that shortcut.
        – Dubu
        Mar 10 '16 at 11:30




        4




        4




        Huh, that is a handy shortcut for "$OLDPWD". Why three separate cp commands, though? cp -a ~-/file[1-3].txt .
        – Peter Cordes
        Mar 10 '16 at 15:32




        Huh, that is a handy shortcut for "$OLDPWD". Why three separate cp commands, though? cp -a ~-/file[1-3].txt .
        – Peter Cordes
        Mar 10 '16 at 15:32




        4




        4




        Actually, the three cp's are examples. In the real world, wildcard characters can also be used to simplify the copy task.
        – Anderson M. Gomes
        Mar 10 '16 at 16:39




        Actually, the three cp's are examples. In the real world, wildcard characters can also be used to simplify the copy task.
        – Anderson M. Gomes
        Mar 10 '16 at 16:39




        2




        2




        I was going to mention something about pushd and parsing dirs...but this is far, far better. I suggest you add the fact that "$OLDPWD" is exactly equivalent to ~- and is more portable (helpful for those not using bash.)
        – Wildcard
        Mar 11 '16 at 5:54




        I was going to mention something about pushd and parsing dirs...but this is far, far better. I suggest you add the fact that "$OLDPWD" is exactly equivalent to ~- and is more portable (helpful for those not using bash.)
        – Wildcard
        Mar 11 '16 at 5:54




        1




        1




        ~+ is likewise a shortcut for "$PWD"
        – Paul Evans
        Mar 12 '16 at 21:23




        ~+ is likewise a shortcut for "$PWD"
        – Paul Evans
        Mar 12 '16 at 21:23













        10














        If I saw that situation coming as a one-off, I might:



        a=`pwd`
        cd /somewhere/else
        cp "$a/myfile" .


        If there were directories that I found myself copying files out of semi-regularly, I would probably define some mnemonic variables for them in my .profile.



        Edited to add:



        After sleeping on it, I wondered how closely I could get to other GUI / OS behaviors where you select some number of files, "cut" or "copy" them, then "paste" them somewhere else. The best selection mechanism I could come up with was your brain/preferences plus the shell's globbing feature. I'm not very creative with naming, but this is the basic idea (in Bash syntax):



        function copyfiles {
        _copypastefiles=("$@")
        _copypastesrc="$PWD"
        _copypastemode=copy
        }

        function cutfiles {
        _copypastefiles=("$@")
        _copypastesrc="$PWD"
        _copypastemode=cut
        }

        function pastefiles {
        for f in "${_copypastefiles[@]}"
        do
        cp "${_copypastesrc}/$f" .
        if [[ ${_copypastemode} = "cut" ]]
        then
        rm "${_copypastesrc}/$f"
        fi
        done
        }


        To use it, put the code into ~/.bash_profile, then cd to the source directory and run either copyfiles glob*here or cutfiles glob*here. All that happens is that your shell expands the globs and puts those filenames into an array. You then cd to the destination directory and run pastefiles, which executes a cp command for each source file. If you had previously "cut" the files, then pastefiles also removes the source file (or, tries to). This doesn't do any error-checking (of existing files, before potentially clobbering them with the cp; or that you have permissions to remove the files during a "cut", or that you can re-access the source directory after you move out of it).






        share|improve this answer



















        • 3




          For your one-off, $OLDPWD already exists, which can be shortened to ~- in bash and zsh.
          – Gilles
          Mar 10 '16 at 19:50


















        10














        If I saw that situation coming as a one-off, I might:



        a=`pwd`
        cd /somewhere/else
        cp "$a/myfile" .


        If there were directories that I found myself copying files out of semi-regularly, I would probably define some mnemonic variables for them in my .profile.



        Edited to add:



        After sleeping on it, I wondered how closely I could get to other GUI / OS behaviors where you select some number of files, "cut" or "copy" them, then "paste" them somewhere else. The best selection mechanism I could come up with was your brain/preferences plus the shell's globbing feature. I'm not very creative with naming, but this is the basic idea (in Bash syntax):



        function copyfiles {
        _copypastefiles=("$@")
        _copypastesrc="$PWD"
        _copypastemode=copy
        }

        function cutfiles {
        _copypastefiles=("$@")
        _copypastesrc="$PWD"
        _copypastemode=cut
        }

        function pastefiles {
        for f in "${_copypastefiles[@]}"
        do
        cp "${_copypastesrc}/$f" .
        if [[ ${_copypastemode} = "cut" ]]
        then
        rm "${_copypastesrc}/$f"
        fi
        done
        }


        To use it, put the code into ~/.bash_profile, then cd to the source directory and run either copyfiles glob*here or cutfiles glob*here. All that happens is that your shell expands the globs and puts those filenames into an array. You then cd to the destination directory and run pastefiles, which executes a cp command for each source file. If you had previously "cut" the files, then pastefiles also removes the source file (or, tries to). This doesn't do any error-checking (of existing files, before potentially clobbering them with the cp; or that you have permissions to remove the files during a "cut", or that you can re-access the source directory after you move out of it).






        share|improve this answer



















        • 3




          For your one-off, $OLDPWD already exists, which can be shortened to ~- in bash and zsh.
          – Gilles
          Mar 10 '16 at 19:50
















        10












        10








        10






        If I saw that situation coming as a one-off, I might:



        a=`pwd`
        cd /somewhere/else
        cp "$a/myfile" .


        If there were directories that I found myself copying files out of semi-regularly, I would probably define some mnemonic variables for them in my .profile.



        Edited to add:



        After sleeping on it, I wondered how closely I could get to other GUI / OS behaviors where you select some number of files, "cut" or "copy" them, then "paste" them somewhere else. The best selection mechanism I could come up with was your brain/preferences plus the shell's globbing feature. I'm not very creative with naming, but this is the basic idea (in Bash syntax):



        function copyfiles {
        _copypastefiles=("$@")
        _copypastesrc="$PWD"
        _copypastemode=copy
        }

        function cutfiles {
        _copypastefiles=("$@")
        _copypastesrc="$PWD"
        _copypastemode=cut
        }

        function pastefiles {
        for f in "${_copypastefiles[@]}"
        do
        cp "${_copypastesrc}/$f" .
        if [[ ${_copypastemode} = "cut" ]]
        then
        rm "${_copypastesrc}/$f"
        fi
        done
        }


        To use it, put the code into ~/.bash_profile, then cd to the source directory and run either copyfiles glob*here or cutfiles glob*here. All that happens is that your shell expands the globs and puts those filenames into an array. You then cd to the destination directory and run pastefiles, which executes a cp command for each source file. If you had previously "cut" the files, then pastefiles also removes the source file (or, tries to). This doesn't do any error-checking (of existing files, before potentially clobbering them with the cp; or that you have permissions to remove the files during a "cut", or that you can re-access the source directory after you move out of it).






        share|improve this answer














        If I saw that situation coming as a one-off, I might:



        a=`pwd`
        cd /somewhere/else
        cp "$a/myfile" .


        If there were directories that I found myself copying files out of semi-regularly, I would probably define some mnemonic variables for them in my .profile.



        Edited to add:



        After sleeping on it, I wondered how closely I could get to other GUI / OS behaviors where you select some number of files, "cut" or "copy" them, then "paste" them somewhere else. The best selection mechanism I could come up with was your brain/preferences plus the shell's globbing feature. I'm not very creative with naming, but this is the basic idea (in Bash syntax):



        function copyfiles {
        _copypastefiles=("$@")
        _copypastesrc="$PWD"
        _copypastemode=copy
        }

        function cutfiles {
        _copypastefiles=("$@")
        _copypastesrc="$PWD"
        _copypastemode=cut
        }

        function pastefiles {
        for f in "${_copypastefiles[@]}"
        do
        cp "${_copypastesrc}/$f" .
        if [[ ${_copypastemode} = "cut" ]]
        then
        rm "${_copypastesrc}/$f"
        fi
        done
        }


        To use it, put the code into ~/.bash_profile, then cd to the source directory and run either copyfiles glob*here or cutfiles glob*here. All that happens is that your shell expands the globs and puts those filenames into an array. You then cd to the destination directory and run pastefiles, which executes a cp command for each source file. If you had previously "cut" the files, then pastefiles also removes the source file (or, tries to). This doesn't do any error-checking (of existing files, before potentially clobbering them with the cp; or that you have permissions to remove the files during a "cut", or that you can re-access the source directory after you move out of it).







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 10 '16 at 12:15

























        answered Mar 10 '16 at 4:16









        Jeff Schaller

        38.7k1053125




        38.7k1053125








        • 3




          For your one-off, $OLDPWD already exists, which can be shortened to ~- in bash and zsh.
          – Gilles
          Mar 10 '16 at 19:50
















        • 3




          For your one-off, $OLDPWD already exists, which can be shortened to ~- in bash and zsh.
          – Gilles
          Mar 10 '16 at 19:50










        3




        3




        For your one-off, $OLDPWD already exists, which can be shortened to ~- in bash and zsh.
        – Gilles
        Mar 10 '16 at 19:50






        For your one-off, $OLDPWD already exists, which can be shortened to ~- in bash and zsh.
        – Gilles
        Mar 10 '16 at 19:50













        5














        I think the ~- is the right answer, but note that bash has a built-in line editor that can copy/paste text.



        If you are in emacs mode you can recall your cd command from the history, and use Control-u to kill the line into the bash "clipboard" called the kill-ring (there are other ways too). You can then yank this string into a new command at any time with Control-y. Obviously, in your example this depends on you having used an absolute directory name in your cd command.



        You can also use the interesting default key-binding of Meta-.. This copies the last word from the previous command into your current line. If repeated, each time it goes back one command in the history. So if you do a cd /x, then cd /y followed by cdMeta-.Meta-. you will have /x in your input.






        share|improve this answer


























          5














          I think the ~- is the right answer, but note that bash has a built-in line editor that can copy/paste text.



          If you are in emacs mode you can recall your cd command from the history, and use Control-u to kill the line into the bash "clipboard" called the kill-ring (there are other ways too). You can then yank this string into a new command at any time with Control-y. Obviously, in your example this depends on you having used an absolute directory name in your cd command.



          You can also use the interesting default key-binding of Meta-.. This copies the last word from the previous command into your current line. If repeated, each time it goes back one command in the history. So if you do a cd /x, then cd /y followed by cdMeta-.Meta-. you will have /x in your input.






          share|improve this answer
























            5












            5








            5






            I think the ~- is the right answer, but note that bash has a built-in line editor that can copy/paste text.



            If you are in emacs mode you can recall your cd command from the history, and use Control-u to kill the line into the bash "clipboard" called the kill-ring (there are other ways too). You can then yank this string into a new command at any time with Control-y. Obviously, in your example this depends on you having used an absolute directory name in your cd command.



            You can also use the interesting default key-binding of Meta-.. This copies the last word from the previous command into your current line. If repeated, each time it goes back one command in the history. So if you do a cd /x, then cd /y followed by cdMeta-.Meta-. you will have /x in your input.






            share|improve this answer












            I think the ~- is the right answer, but note that bash has a built-in line editor that can copy/paste text.



            If you are in emacs mode you can recall your cd command from the history, and use Control-u to kill the line into the bash "clipboard" called the kill-ring (there are other ways too). You can then yank this string into a new command at any time with Control-y. Obviously, in your example this depends on you having used an absolute directory name in your cd command.



            You can also use the interesting default key-binding of Meta-.. This copies the last word from the previous command into your current line. If repeated, each time it goes back one command in the history. So if you do a cd /x, then cd /y followed by cdMeta-.Meta-. you will have /x in your input.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 10 '16 at 7:19









            meuh

            31.4k11854




            31.4k11854























                5














                Expanding on the answer from Anderson M. Gomes, Bash allows you to refer to any prior directory in your directory stack by typing ~N (or ~+N) where N is the position on the dir stack. For example:



                # go some places
                $ cd /path/to/source/directory
                $ pushd /path/to/destination/directory
                $ pushd $HOME
                $ pushd /tmp

                # show the current dir stack
                $ dirs -v
                0 /tmp
                1 ~
                2 /path/to/destination/directory
                3 /path/to/source/directory


                Now you can copy a file between two past directories, neither of them the current one, with:



                cp -v ~3/file1.txt ~2




                To solve the original poster's problem, you would do:



                $ cd /path/to/source/directory
                $ pushd /path/to/destination/directory

                # show the current dir stack
                $ dirs -v
                0 /path/to/destination/directory
                1 /path/to/source/directory

                # copy
                cp -v ~1/file[123].txt .


                With a large set of files, you could list their names in a manifest file and then do the copy from the source dir:



                $ cd /path/to/destination/directory
                $ pushd /path/to/source/directory

                # copy
                cp -v $(cat files_to_copy.list) ~1


                See also: this section of the Bash man page





                Similarly, in Tcsh, you can use the =2 notation (rather than ~2) to refer to the second dir on your dir stack.



                See also: this section of the Tcsh man page






                share|improve this answer




























                  5














                  Expanding on the answer from Anderson M. Gomes, Bash allows you to refer to any prior directory in your directory stack by typing ~N (or ~+N) where N is the position on the dir stack. For example:



                  # go some places
                  $ cd /path/to/source/directory
                  $ pushd /path/to/destination/directory
                  $ pushd $HOME
                  $ pushd /tmp

                  # show the current dir stack
                  $ dirs -v
                  0 /tmp
                  1 ~
                  2 /path/to/destination/directory
                  3 /path/to/source/directory


                  Now you can copy a file between two past directories, neither of them the current one, with:



                  cp -v ~3/file1.txt ~2




                  To solve the original poster's problem, you would do:



                  $ cd /path/to/source/directory
                  $ pushd /path/to/destination/directory

                  # show the current dir stack
                  $ dirs -v
                  0 /path/to/destination/directory
                  1 /path/to/source/directory

                  # copy
                  cp -v ~1/file[123].txt .


                  With a large set of files, you could list their names in a manifest file and then do the copy from the source dir:



                  $ cd /path/to/destination/directory
                  $ pushd /path/to/source/directory

                  # copy
                  cp -v $(cat files_to_copy.list) ~1


                  See also: this section of the Bash man page





                  Similarly, in Tcsh, you can use the =2 notation (rather than ~2) to refer to the second dir on your dir stack.



                  See also: this section of the Tcsh man page






                  share|improve this answer


























                    5












                    5








                    5






                    Expanding on the answer from Anderson M. Gomes, Bash allows you to refer to any prior directory in your directory stack by typing ~N (or ~+N) where N is the position on the dir stack. For example:



                    # go some places
                    $ cd /path/to/source/directory
                    $ pushd /path/to/destination/directory
                    $ pushd $HOME
                    $ pushd /tmp

                    # show the current dir stack
                    $ dirs -v
                    0 /tmp
                    1 ~
                    2 /path/to/destination/directory
                    3 /path/to/source/directory


                    Now you can copy a file between two past directories, neither of them the current one, with:



                    cp -v ~3/file1.txt ~2




                    To solve the original poster's problem, you would do:



                    $ cd /path/to/source/directory
                    $ pushd /path/to/destination/directory

                    # show the current dir stack
                    $ dirs -v
                    0 /path/to/destination/directory
                    1 /path/to/source/directory

                    # copy
                    cp -v ~1/file[123].txt .


                    With a large set of files, you could list their names in a manifest file and then do the copy from the source dir:



                    $ cd /path/to/destination/directory
                    $ pushd /path/to/source/directory

                    # copy
                    cp -v $(cat files_to_copy.list) ~1


                    See also: this section of the Bash man page





                    Similarly, in Tcsh, you can use the =2 notation (rather than ~2) to refer to the second dir on your dir stack.



                    See also: this section of the Tcsh man page






                    share|improve this answer














                    Expanding on the answer from Anderson M. Gomes, Bash allows you to refer to any prior directory in your directory stack by typing ~N (or ~+N) where N is the position on the dir stack. For example:



                    # go some places
                    $ cd /path/to/source/directory
                    $ pushd /path/to/destination/directory
                    $ pushd $HOME
                    $ pushd /tmp

                    # show the current dir stack
                    $ dirs -v
                    0 /tmp
                    1 ~
                    2 /path/to/destination/directory
                    3 /path/to/source/directory


                    Now you can copy a file between two past directories, neither of them the current one, with:



                    cp -v ~3/file1.txt ~2




                    To solve the original poster's problem, you would do:



                    $ cd /path/to/source/directory
                    $ pushd /path/to/destination/directory

                    # show the current dir stack
                    $ dirs -v
                    0 /path/to/destination/directory
                    1 /path/to/source/directory

                    # copy
                    cp -v ~1/file[123].txt .


                    With a large set of files, you could list their names in a manifest file and then do the copy from the source dir:



                    $ cd /path/to/destination/directory
                    $ pushd /path/to/source/directory

                    # copy
                    cp -v $(cat files_to_copy.list) ~1


                    See also: this section of the Bash man page





                    Similarly, in Tcsh, you can use the =2 notation (rather than ~2) to refer to the second dir on your dir stack.



                    See also: this section of the Tcsh man page







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 17 at 2:46

























                    answered Mar 11 '16 at 23:07









                    jskroch

                    935




                    935























                        4














                        when you are in the first directory, lets say the source or src in short, execute



                        src=${PWD}


                        then cd in to second directory and execute:



                        cp -i ${src}/filename .


                        the -i option will ask if you want to overwrite, if there is a duplicate file






                        share|improve this answer





















                        • Thanks. It is even better without specifying the filename.
                          – Tim
                          Mar 10 '16 at 4:14
















                        4














                        when you are in the first directory, lets say the source or src in short, execute



                        src=${PWD}


                        then cd in to second directory and execute:



                        cp -i ${src}/filename .


                        the -i option will ask if you want to overwrite, if there is a duplicate file






                        share|improve this answer





















                        • Thanks. It is even better without specifying the filename.
                          – Tim
                          Mar 10 '16 at 4:14














                        4












                        4








                        4






                        when you are in the first directory, lets say the source or src in short, execute



                        src=${PWD}


                        then cd in to second directory and execute:



                        cp -i ${src}/filename .


                        the -i option will ask if you want to overwrite, if there is a duplicate file






                        share|improve this answer












                        when you are in the first directory, lets say the source or src in short, execute



                        src=${PWD}


                        then cd in to second directory and execute:



                        cp -i ${src}/filename .


                        the -i option will ask if you want to overwrite, if there is a duplicate file







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Mar 10 '16 at 4:11









                        MelBurslan

                        5,29011533




                        5,29011533












                        • Thanks. It is even better without specifying the filename.
                          – Tim
                          Mar 10 '16 at 4:14


















                        • Thanks. It is even better without specifying the filename.
                          – Tim
                          Mar 10 '16 at 4:14
















                        Thanks. It is even better without specifying the filename.
                        – Tim
                        Mar 10 '16 at 4:14




                        Thanks. It is even better without specifying the filename.
                        – Tim
                        Mar 10 '16 at 4:14











                        4














                        A variation on anderson-m-gomes response.
                        Using Bash, I would just visit the directories:



                        $ cd /path/to/source/directory
                        $ cd /path/to/destination/directory


                        Then, I would use the variable $OLDPWD, which points to the previous directory:



                        $ cp -v $OLDPWD/file1.txt .


                        If one wants to visit directories in reverse order, then:



                        $ cp -v fileA.txt $OLDPWD/





                        share|improve this answer

















                        • 3




                          +1, but you forgot to "quote" your variable expansions. If $OLDPWD contains spaces, this breaks. Also, I always use cp -a. Also, it's unfortunate that tab-completion is broken on variable expansions. You can use ctrl-alt-e to shell-expand the current command line, though, after typing the $OLDPWD part.
                          – Peter Cordes
                          Mar 10 '16 at 15:30






                        • 1




                          ~- is a shortcut for $OLDPWD
                          – Gilles
                          Mar 10 '16 at 19:51










                        • I was just pointing out another variation, since Unix/Linux is full of them. Funny, that I've been using Linux for >20 years, and I'd never seen ~- before. Plus, $OLDPWD is easy to remember.
                          – Scott Carlson
                          Mar 14 '16 at 17:54
















                        4














                        A variation on anderson-m-gomes response.
                        Using Bash, I would just visit the directories:



                        $ cd /path/to/source/directory
                        $ cd /path/to/destination/directory


                        Then, I would use the variable $OLDPWD, which points to the previous directory:



                        $ cp -v $OLDPWD/file1.txt .


                        If one wants to visit directories in reverse order, then:



                        $ cp -v fileA.txt $OLDPWD/





                        share|improve this answer

















                        • 3




                          +1, but you forgot to "quote" your variable expansions. If $OLDPWD contains spaces, this breaks. Also, I always use cp -a. Also, it's unfortunate that tab-completion is broken on variable expansions. You can use ctrl-alt-e to shell-expand the current command line, though, after typing the $OLDPWD part.
                          – Peter Cordes
                          Mar 10 '16 at 15:30






                        • 1




                          ~- is a shortcut for $OLDPWD
                          – Gilles
                          Mar 10 '16 at 19:51










                        • I was just pointing out another variation, since Unix/Linux is full of them. Funny, that I've been using Linux for >20 years, and I'd never seen ~- before. Plus, $OLDPWD is easy to remember.
                          – Scott Carlson
                          Mar 14 '16 at 17:54














                        4












                        4








                        4






                        A variation on anderson-m-gomes response.
                        Using Bash, I would just visit the directories:



                        $ cd /path/to/source/directory
                        $ cd /path/to/destination/directory


                        Then, I would use the variable $OLDPWD, which points to the previous directory:



                        $ cp -v $OLDPWD/file1.txt .


                        If one wants to visit directories in reverse order, then:



                        $ cp -v fileA.txt $OLDPWD/





                        share|improve this answer












                        A variation on anderson-m-gomes response.
                        Using Bash, I would just visit the directories:



                        $ cd /path/to/source/directory
                        $ cd /path/to/destination/directory


                        Then, I would use the variable $OLDPWD, which points to the previous directory:



                        $ cp -v $OLDPWD/file1.txt .


                        If one wants to visit directories in reverse order, then:



                        $ cp -v fileA.txt $OLDPWD/






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Mar 10 '16 at 13:41









                        Scott Carlson

                        1412




                        1412








                        • 3




                          +1, but you forgot to "quote" your variable expansions. If $OLDPWD contains spaces, this breaks. Also, I always use cp -a. Also, it's unfortunate that tab-completion is broken on variable expansions. You can use ctrl-alt-e to shell-expand the current command line, though, after typing the $OLDPWD part.
                          – Peter Cordes
                          Mar 10 '16 at 15:30






                        • 1




                          ~- is a shortcut for $OLDPWD
                          – Gilles
                          Mar 10 '16 at 19:51










                        • I was just pointing out another variation, since Unix/Linux is full of them. Funny, that I've been using Linux for >20 years, and I'd never seen ~- before. Plus, $OLDPWD is easy to remember.
                          – Scott Carlson
                          Mar 14 '16 at 17:54














                        • 3




                          +1, but you forgot to "quote" your variable expansions. If $OLDPWD contains spaces, this breaks. Also, I always use cp -a. Also, it's unfortunate that tab-completion is broken on variable expansions. You can use ctrl-alt-e to shell-expand the current command line, though, after typing the $OLDPWD part.
                          – Peter Cordes
                          Mar 10 '16 at 15:30






                        • 1




                          ~- is a shortcut for $OLDPWD
                          – Gilles
                          Mar 10 '16 at 19:51










                        • I was just pointing out another variation, since Unix/Linux is full of them. Funny, that I've been using Linux for >20 years, and I'd never seen ~- before. Plus, $OLDPWD is easy to remember.
                          – Scott Carlson
                          Mar 14 '16 at 17:54








                        3




                        3




                        +1, but you forgot to "quote" your variable expansions. If $OLDPWD contains spaces, this breaks. Also, I always use cp -a. Also, it's unfortunate that tab-completion is broken on variable expansions. You can use ctrl-alt-e to shell-expand the current command line, though, after typing the $OLDPWD part.
                        – Peter Cordes
                        Mar 10 '16 at 15:30




                        +1, but you forgot to "quote" your variable expansions. If $OLDPWD contains spaces, this breaks. Also, I always use cp -a. Also, it's unfortunate that tab-completion is broken on variable expansions. You can use ctrl-alt-e to shell-expand the current command line, though, after typing the $OLDPWD part.
                        – Peter Cordes
                        Mar 10 '16 at 15:30




                        1




                        1




                        ~- is a shortcut for $OLDPWD
                        – Gilles
                        Mar 10 '16 at 19:51




                        ~- is a shortcut for $OLDPWD
                        – Gilles
                        Mar 10 '16 at 19:51












                        I was just pointing out another variation, since Unix/Linux is full of them. Funny, that I've been using Linux for >20 years, and I'd never seen ~- before. Plus, $OLDPWD is easy to remember.
                        – Scott Carlson
                        Mar 14 '16 at 17:54




                        I was just pointing out another variation, since Unix/Linux is full of them. Funny, that I've been using Linux for >20 years, and I'd never seen ~- before. Plus, $OLDPWD is easy to remember.
                        – Scott Carlson
                        Mar 14 '16 at 17:54











                        3














                        If in bash, I would use pushd and popd. These commands keep a handy FIFO stack of directories for later use. You can consult the stack anytime using dirs.



                        As such I would do:



                        pushd .
                        cd /somewhere/else
                        cp "`popd`/myfile"





                        share|improve this answer




























                          3














                          If in bash, I would use pushd and popd. These commands keep a handy FIFO stack of directories for later use. You can consult the stack anytime using dirs.



                          As such I would do:



                          pushd .
                          cd /somewhere/else
                          cp "`popd`/myfile"





                          share|improve this answer


























                            3












                            3








                            3






                            If in bash, I would use pushd and popd. These commands keep a handy FIFO stack of directories for later use. You can consult the stack anytime using dirs.



                            As such I would do:



                            pushd .
                            cd /somewhere/else
                            cp "`popd`/myfile"





                            share|improve this answer














                            If in bash, I would use pushd and popd. These commands keep a handy FIFO stack of directories for later use. You can consult the stack anytime using dirs.



                            As such I would do:



                            pushd .
                            cd /somewhere/else
                            cp "`popd`/myfile"






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Mar 10 '16 at 15:34

























                            answered Mar 10 '16 at 7:12









                            Rui F Ribeiro

                            38.9k1479129




                            38.9k1479129























                                2














                                You can use xclip:



                                NAME
                                xclip - command line interface to X selections (clipboard)

                                SYNOPSIS
                                xclip [OPTION] [FILE]...

                                DESCRIPTION
                                Reads from standard in, or from one or more files, and makes the data available as an X selection for pasting
                                into X applications. Prints current X selection to standard out.


                                Example:



                                $ cd /path/to/dir1
                                $ xclip-copyfile file1 file2
                                $ cd /path/to/dir2
                                $ xclip-pastefile
                                file1 file2


                                Also visit xsel.






                                share|improve this answer























                                • That does a tar | gzip into / out of the X clipboard. Kinda clunky compared to cp, and doesn't generalize to making symlinks or hardlinks. (cp -as or cp -al)
                                  – Peter Cordes
                                  Mar 10 '16 at 15:44
















                                2














                                You can use xclip:



                                NAME
                                xclip - command line interface to X selections (clipboard)

                                SYNOPSIS
                                xclip [OPTION] [FILE]...

                                DESCRIPTION
                                Reads from standard in, or from one or more files, and makes the data available as an X selection for pasting
                                into X applications. Prints current X selection to standard out.


                                Example:



                                $ cd /path/to/dir1
                                $ xclip-copyfile file1 file2
                                $ cd /path/to/dir2
                                $ xclip-pastefile
                                file1 file2


                                Also visit xsel.






                                share|improve this answer























                                • That does a tar | gzip into / out of the X clipboard. Kinda clunky compared to cp, and doesn't generalize to making symlinks or hardlinks. (cp -as or cp -al)
                                  – Peter Cordes
                                  Mar 10 '16 at 15:44














                                2












                                2








                                2






                                You can use xclip:



                                NAME
                                xclip - command line interface to X selections (clipboard)

                                SYNOPSIS
                                xclip [OPTION] [FILE]...

                                DESCRIPTION
                                Reads from standard in, or from one or more files, and makes the data available as an X selection for pasting
                                into X applications. Prints current X selection to standard out.


                                Example:



                                $ cd /path/to/dir1
                                $ xclip-copyfile file1 file2
                                $ cd /path/to/dir2
                                $ xclip-pastefile
                                file1 file2


                                Also visit xsel.






                                share|improve this answer














                                You can use xclip:



                                NAME
                                xclip - command line interface to X selections (clipboard)

                                SYNOPSIS
                                xclip [OPTION] [FILE]...

                                DESCRIPTION
                                Reads from standard in, or from one or more files, and makes the data available as an X selection for pasting
                                into X applications. Prints current X selection to standard out.


                                Example:



                                $ cd /path/to/dir1
                                $ xclip-copyfile file1 file2
                                $ cd /path/to/dir2
                                $ xclip-pastefile
                                file1 file2


                                Also visit xsel.







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Mar 10 '16 at 10:39

























                                answered Mar 10 '16 at 10:12









                                Pandya

                                8,5591449103




                                8,5591449103












                                • That does a tar | gzip into / out of the X clipboard. Kinda clunky compared to cp, and doesn't generalize to making symlinks or hardlinks. (cp -as or cp -al)
                                  – Peter Cordes
                                  Mar 10 '16 at 15:44


















                                • That does a tar | gzip into / out of the X clipboard. Kinda clunky compared to cp, and doesn't generalize to making symlinks or hardlinks. (cp -as or cp -al)
                                  – Peter Cordes
                                  Mar 10 '16 at 15:44
















                                That does a tar | gzip into / out of the X clipboard. Kinda clunky compared to cp, and doesn't generalize to making symlinks or hardlinks. (cp -as or cp -al)
                                – Peter Cordes
                                Mar 10 '16 at 15:44




                                That does a tar | gzip into / out of the X clipboard. Kinda clunky compared to cp, and doesn't generalize to making symlinks or hardlinks. (cp -as or cp -al)
                                – Peter Cordes
                                Mar 10 '16 at 15:44


















                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f268818%2fclipboard-for-copying-and-pasting-files-in-command-line%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Morgemoulin

                                Scott Moir

                                Souastre