Linux console equivalent to gui copy/paste file/directory scenario












2















How to simply recreate copy/paste functionality like in gui environments?



My typical scenario for copying file/directory in Linux console is:



cp source_path target_path


Sometimes paths are relative, sometimes absolute, but I need to provide them both. It works, but there are situations where I would like to recreate scenario from gui which is:



1. go to source directory
2. copy file/directory
3. go to target directory
4. paste file/directory


I imagine something like



cd source_directory_path
copy_to_stash source_name
cd target_directory_path
paste_from_stash [optional_new_target_name]


I know that there is a xclip app, but a documentation says that it copies content of a file, not a file handle. Also, I can use $OLDPWD variable and expand it when I copy file, but this is not a solution without some cumbersome.



Is there some simple, general, keyboard only, not awkward to use equivalent? I don't want to use additional managers like ranger, midnight commander, only cli.










share|improve this question



























    2















    How to simply recreate copy/paste functionality like in gui environments?



    My typical scenario for copying file/directory in Linux console is:



    cp source_path target_path


    Sometimes paths are relative, sometimes absolute, but I need to provide them both. It works, but there are situations where I would like to recreate scenario from gui which is:



    1. go to source directory
    2. copy file/directory
    3. go to target directory
    4. paste file/directory


    I imagine something like



    cd source_directory_path
    copy_to_stash source_name
    cd target_directory_path
    paste_from_stash [optional_new_target_name]


    I know that there is a xclip app, but a documentation says that it copies content of a file, not a file handle. Also, I can use $OLDPWD variable and expand it when I copy file, but this is not a solution without some cumbersome.



    Is there some simple, general, keyboard only, not awkward to use equivalent? I don't want to use additional managers like ranger, midnight commander, only cli.










    share|improve this question

























      2












      2








      2








      How to simply recreate copy/paste functionality like in gui environments?



      My typical scenario for copying file/directory in Linux console is:



      cp source_path target_path


      Sometimes paths are relative, sometimes absolute, but I need to provide them both. It works, but there are situations where I would like to recreate scenario from gui which is:



      1. go to source directory
      2. copy file/directory
      3. go to target directory
      4. paste file/directory


      I imagine something like



      cd source_directory_path
      copy_to_stash source_name
      cd target_directory_path
      paste_from_stash [optional_new_target_name]


      I know that there is a xclip app, but a documentation says that it copies content of a file, not a file handle. Also, I can use $OLDPWD variable and expand it when I copy file, but this is not a solution without some cumbersome.



      Is there some simple, general, keyboard only, not awkward to use equivalent? I don't want to use additional managers like ranger, midnight commander, only cli.










      share|improve this question














      How to simply recreate copy/paste functionality like in gui environments?



      My typical scenario for copying file/directory in Linux console is:



      cp source_path target_path


      Sometimes paths are relative, sometimes absolute, but I need to provide them both. It works, but there are situations where I would like to recreate scenario from gui which is:



      1. go to source directory
      2. copy file/directory
      3. go to target directory
      4. paste file/directory


      I imagine something like



      cd source_directory_path
      copy_to_stash source_name
      cd target_directory_path
      paste_from_stash [optional_new_target_name]


      I know that there is a xclip app, but a documentation says that it copies content of a file, not a file handle. Also, I can use $OLDPWD variable and expand it when I copy file, but this is not a solution without some cumbersome.



      Is there some simple, general, keyboard only, not awkward to use equivalent? I don't want to use additional managers like ranger, midnight commander, only cli.







      linux command-line copy-paste console






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 14 at 13:37









      NoMoreMrNiceGaiusNoMoreMrNiceGaius

      1156




      1156






















          2 Answers
          2






          active

          oldest

          votes


















          2














          You should be able to do this with some basic functions, and the shell's $PWD variable to get the absolute path, to save a name you specify & later copy it wherever you happen to be. Here's two for bash (dash/sh might just require using test or [ instead of [[):



          #!/bin/bash
          # source me with one of:
          # source [file]
          # . [file]

          # Initialize
          sa_file=

          sa(){
          # Fuction to save a file in the current PWD
          if [[ -e "$PWD/$1" ]]; then
          sa_file=$PWD/$1
          echo "Saved for later: $sa_file"
          else
          echo "Error: file $PWD/$1 does not exist"
          fi
          }


          pa(){
          # Paste if file exists, to $1 if exists
          if [[ -e "$sa_file" ]]; then
          if [[ $1 ]]; then
          cp -v "$sa_file" "$1"
          else
          cp -v "$sa_file" .
          fi
          else
          echo "Error: file $sa_file does not exist, could not copy"
          fi
          }


          I used the names sa for save, and pa for paste [since less typing = better right?] but naming them anything would work, like copy_to_stash.






          share|improve this answer































            0














            You could use xclip to copy and paste the paths to files.



            cd source_directory_path
            realpath some_file | xclip # Copy the path to a file
            cd target_directory_path
            cp "$(xclip -o)" . # Copy ("paste") the file to the current directory





            share|improve this answer


























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              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: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              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%2fsuperuser.com%2fquestions%2f1405696%2flinux-console-equivalent-to-gui-copy-paste-file-directory-scenario%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              You should be able to do this with some basic functions, and the shell's $PWD variable to get the absolute path, to save a name you specify & later copy it wherever you happen to be. Here's two for bash (dash/sh might just require using test or [ instead of [[):



              #!/bin/bash
              # source me with one of:
              # source [file]
              # . [file]

              # Initialize
              sa_file=

              sa(){
              # Fuction to save a file in the current PWD
              if [[ -e "$PWD/$1" ]]; then
              sa_file=$PWD/$1
              echo "Saved for later: $sa_file"
              else
              echo "Error: file $PWD/$1 does not exist"
              fi
              }


              pa(){
              # Paste if file exists, to $1 if exists
              if [[ -e "$sa_file" ]]; then
              if [[ $1 ]]; then
              cp -v "$sa_file" "$1"
              else
              cp -v "$sa_file" .
              fi
              else
              echo "Error: file $sa_file does not exist, could not copy"
              fi
              }


              I used the names sa for save, and pa for paste [since less typing = better right?] but naming them anything would work, like copy_to_stash.






              share|improve this answer




























                2














                You should be able to do this with some basic functions, and the shell's $PWD variable to get the absolute path, to save a name you specify & later copy it wherever you happen to be. Here's two for bash (dash/sh might just require using test or [ instead of [[):



                #!/bin/bash
                # source me with one of:
                # source [file]
                # . [file]

                # Initialize
                sa_file=

                sa(){
                # Fuction to save a file in the current PWD
                if [[ -e "$PWD/$1" ]]; then
                sa_file=$PWD/$1
                echo "Saved for later: $sa_file"
                else
                echo "Error: file $PWD/$1 does not exist"
                fi
                }


                pa(){
                # Paste if file exists, to $1 if exists
                if [[ -e "$sa_file" ]]; then
                if [[ $1 ]]; then
                cp -v "$sa_file" "$1"
                else
                cp -v "$sa_file" .
                fi
                else
                echo "Error: file $sa_file does not exist, could not copy"
                fi
                }


                I used the names sa for save, and pa for paste [since less typing = better right?] but naming them anything would work, like copy_to_stash.






                share|improve this answer


























                  2












                  2








                  2







                  You should be able to do this with some basic functions, and the shell's $PWD variable to get the absolute path, to save a name you specify & later copy it wherever you happen to be. Here's two for bash (dash/sh might just require using test or [ instead of [[):



                  #!/bin/bash
                  # source me with one of:
                  # source [file]
                  # . [file]

                  # Initialize
                  sa_file=

                  sa(){
                  # Fuction to save a file in the current PWD
                  if [[ -e "$PWD/$1" ]]; then
                  sa_file=$PWD/$1
                  echo "Saved for later: $sa_file"
                  else
                  echo "Error: file $PWD/$1 does not exist"
                  fi
                  }


                  pa(){
                  # Paste if file exists, to $1 if exists
                  if [[ -e "$sa_file" ]]; then
                  if [[ $1 ]]; then
                  cp -v "$sa_file" "$1"
                  else
                  cp -v "$sa_file" .
                  fi
                  else
                  echo "Error: file $sa_file does not exist, could not copy"
                  fi
                  }


                  I used the names sa for save, and pa for paste [since less typing = better right?] but naming them anything would work, like copy_to_stash.






                  share|improve this answer













                  You should be able to do this with some basic functions, and the shell's $PWD variable to get the absolute path, to save a name you specify & later copy it wherever you happen to be. Here's two for bash (dash/sh might just require using test or [ instead of [[):



                  #!/bin/bash
                  # source me with one of:
                  # source [file]
                  # . [file]

                  # Initialize
                  sa_file=

                  sa(){
                  # Fuction to save a file in the current PWD
                  if [[ -e "$PWD/$1" ]]; then
                  sa_file=$PWD/$1
                  echo "Saved for later: $sa_file"
                  else
                  echo "Error: file $PWD/$1 does not exist"
                  fi
                  }


                  pa(){
                  # Paste if file exists, to $1 if exists
                  if [[ -e "$sa_file" ]]; then
                  if [[ $1 ]]; then
                  cp -v "$sa_file" "$1"
                  else
                  cp -v "$sa_file" .
                  fi
                  else
                  echo "Error: file $sa_file does not exist, could not copy"
                  fi
                  }


                  I used the names sa for save, and pa for paste [since less typing = better right?] but naming them anything would work, like copy_to_stash.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 15 at 5:17









                  Xen2050Xen2050

                  11.3k31637




                  11.3k31637

























                      0














                      You could use xclip to copy and paste the paths to files.



                      cd source_directory_path
                      realpath some_file | xclip # Copy the path to a file
                      cd target_directory_path
                      cp "$(xclip -o)" . # Copy ("paste") the file to the current directory





                      share|improve this answer






























                        0














                        You could use xclip to copy and paste the paths to files.



                        cd source_directory_path
                        realpath some_file | xclip # Copy the path to a file
                        cd target_directory_path
                        cp "$(xclip -o)" . # Copy ("paste") the file to the current directory





                        share|improve this answer




























                          0












                          0








                          0







                          You could use xclip to copy and paste the paths to files.



                          cd source_directory_path
                          realpath some_file | xclip # Copy the path to a file
                          cd target_directory_path
                          cp "$(xclip -o)" . # Copy ("paste") the file to the current directory





                          share|improve this answer















                          You could use xclip to copy and paste the paths to files.



                          cd source_directory_path
                          realpath some_file | xclip # Copy the path to a file
                          cd target_directory_path
                          cp "$(xclip -o)" . # Copy ("paste") the file to the current directory






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Feb 17 at 2:25

























                          answered Feb 15 at 5:26









                          jamesdlinjamesdlin

                          1,6721120




                          1,6721120






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • 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%2fsuperuser.com%2fquestions%2f1405696%2flinux-console-equivalent-to-gui-copy-paste-file-directory-scenario%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

                              flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                              Mangá

                               ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕