简体   繁体   English

在终端中复制然后粘贴文件

[英]copy THEN paste FILES in terminal

Is there any package that I can use to copy one (or more) file/folder THEN paste into another directory? 是否有可用于将一个(或多个)文件/文件夹然后粘贴到另一个目录的软件包? I am using Ubuntu, and I have the standard terminal + Terminator. 我正在使用Ubuntu,并且具有标准的终端+终结器。

For example, I am looking for a functionality like: 例如,我正在寻找类似的功能:

Folder1$ COPY a.txt
Folder1$ cd ../Folder2
Folder2$ PASTE (a.txt -- optional)

Thank you! 谢谢! I just hate to keep referring to the whole path every time! 我只是讨厌每次都提到整个路径!

This terminal command should work for files: 此终端命令应适用于文件:

cp a.txt ../Folder2/a.txt

And for folders: 对于文件夹:

cp -R myFolder ../Folder2/myFolder

Here's my dumb way to do this, you can add them to your rcfile: 这是我这样做的愚蠢方法,您可以将它们添加到rcfile中:

copy(){
    test -z $1 && echo "No file input!" && return
    test ! -e $1 && echo "File not exist!" && return
    export orig_path="$PWD/$1"
    export orig_name="$1"
}
paste(){
    test -z $orig_path && echo "No copied file!" && return
    if [ "$#" -lt 1 ];then
        dist_name="$PWD/$orig_name"
        if [ -d $orig_path ];then
            cp -r $orig_path $dist_name
        else
            cp $orig_path $dist_name
        fi
        echo "$orig_name pasted."
    else
        dist_name="$PWD/$1"
        if [ -d $orig_path ];then
            cp -r $orig_path $dist_name
        else
            cp $orig_path $dist_name
        fi
        echo "\"$1\" pasted."
    fi
}

This doesn't copy any data to the clipboard, since you want to do this only for not referencing folders, and this works for copying folder as well. 这不会将任何数据复制到剪贴板,因为您只想不引用文件夹就可以这样做,这也适用于复制文件夹。

Take a look at clipboard-files here: https://github.com/larspontoppidan/clipboard-files 在这里看看clipboard-fileshttps : //github.com/larspontoppidan/clipboard-files

It uses xclip to interface the desktop environment clipboard and provides handy commands like ccopy and cpaste that does exactly what was asked for here. 它使用xclip来连接桌面环境剪贴板,并提供方便的命令,如ccopycpaste ,这些命令完全cpaste此处的要求。 As the desktop environment clipboard is used, the commands interact with the copy/pasting in file managers and other programs that use the clipboard for files. 使用桌面环境剪贴板时,命令与文件管理器中的复制/粘贴以及使用剪贴板存储文件的其他程序进行交互。 At least it works on Gnome-like desktops. 至少它可以在类似Gnome的桌面上使用。

Full disclosure, I wrote the script after giving up finding something like it out there :) 完全公开之后,我放弃了在那里找到类似的东西后写了脚本:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM