• 复制文件: cp /home/test.txt /home/test/test.txt 复制文件夹: (复制文件夹中全部内容) /cp -r /home/packageA/* /home/cp/packageB/ 或者 cp -r /home/packageA/. /home/cp/packageB/ (移动文件夹): mv /...


    cp   /home/test.txt    /home/test/test.txt

    /cp -r /home/packageA/* /home/cp/packageB/

    cp -r /home/packageA/. /home/cp/packageB/
    cp -r /server/zt/logs/ /server/zt/motionnet/logs/


    mv /home/packageA /home/packageB
  • linux复制文件命令Fatmawati Achmad Zaenuri/Shutterstock.comFatmawati Achmad Zaenuri / Shutterstock.com installis a versatile file-copying command in Linux and macOS. It’s perfect for the power-...


    Concept art of Bash on an Ubuntu Linux desktop
    Fatmawati Achmad Zaenuri/Shutterstock.comFatmawati Achmad Zaenuri / Shutterstock.com

    install is a versatile file-copying command in Linux and macOS. It’s perfect for the power-user looking for efficiency. Read this article to discover how to work smarter—not harder.

    install是Linux和macOS中的通用文件复制命令。 对于寻求效率的高级用户而言,它是完美的选择。 阅读本文以发现如何更聪明地工作,而不是更努力。

    等待—不是要安装软件吗? (Wait—It’s Not For Installing Software?)

    The install command might have the most misleading name of any of the Linux commands. It doesn’t actually install any software. If you’re trying to install a software package from the command line in Ubuntu or another Debian-based distribution use the apt-get command. On other Linux distributions, use your Linux distribution’s package management tool instead—for example, dnf on Fedora or zypper on openSUSE.

    在任何Linux命令中, install命令的名称可能最具误导性。 它实际上并没有安装任何软件。 如果您试图从Ubuntu或其他基于Debian的发行版中的命令行安装软件包,请使用apt-get命令。 在其他Linux发行版上,请改用Linux发行版的程序包管理工具,例如Fedora上的dnf或openSUSE上的zypper

    那么安装能做什么? (So What Does install Do?)

    In a nutshell  install combines elements from the cp (copy), chown (change owner), chmod (change mode), mkdir (make directory), and strip (strip symbols) commands. It lets you use functions from all of those in one single action.

    简而言之, install结合了cp ( 复制 ), chown ( 更改所有者 ), chmod ( 更改模式 ), mkdir ( make目录 )和strip ( 剥离符号 )命令中的元素。 它使您可以在一次操作中使用所有功能。

    The install command can:


    • Copy files like the cp command.


    • Choose whether to overwrite existing files.

    • Create the target directory if it does not exist, like mkdir.


    • Set the user permission flags of the files, just like the chmod command.


    • Set the owner of the files, just like the chown command.


    • Remove non-essential baggage from executable files, just like the strip command.


    Despite all that functionality, the install command doesn’t have too many options to contend with.


    install man page

    什么时候使用 (When Would You Use It)

    The install command probably won’t be used every day. It’s useful, but only for certain situations. One scenario where install comes into its own is software development. Let’s say you’re programming a new utility. You’ll need to do testing outside of the development environment. To do that you need to copy the new program files to a test directory. The test directory might need to be created, and you need to set the correct permissions and ownership for the files.

    install命令可能不会每天使用。 这很有用,但仅适用于某些情况。 install独有的一种情况是软件开发。 假设您正在编写一个新实用程序。 您需要在开发环境之外进行测试。 为此,您需要将新程序文件复制到测试目录。 可能需要创建测试目录,并且您需要为文件设置正确的权限和所有权。

    Because development is an iterative activity, you can end up doing this sequence of actions many, many times. The install command does all the heavy lifting for you. Finally, when your new utility is ready to be deployed, you can use install to copy it with the correct permissions to its final working location.

    由于开发是一项迭代活动,因此您可以多次完成此一系列操作。 install命令为您完成了所有繁重的工作。 最后,当准备好要部署新实用程序时,可以使用install以正确的权限将其复制到其最终工作位置。

    一个例子 (An Example)

    A programmer is working on just such a new utility, called ana. It consists of an executable binary file and a database. After testing, it must be copied to /usr/local/bin to make it available for all users of the Linux system. You’ll need to substitute the filenames and directory paths in our example for the files and paths you’re using on your computer when you use install.

    程序员正在开发一个名为ana的新实用程序。 它由一个可执行的二进制文件和一个数据库组成。 测试之后,必须将其复制到/usr/local/bin以使其对Linux系统的所有用户可用。 使用install时,您需要用示例中的文件名和目录路径替换您在计算机上使用的文件和路径。

    Until it is ready for release it will be tested in a directory called ~/test/ana. Members of the geek group will have read and execute permissions. Other users will have read and execute permissions also. The install command uses the same numeric representation for permissions as chmod does. Our programmer has decided that the permissions must be set to:

    在准备发布之前,它将在名为~/test/ana的目录中进行测试。 geek组的成员将具有读取和执行权限。 其他用户也将具有读取和执行权限。 install命令使用与chmod相同的数字表示权限。 我们的程序员决定必须将权限设置为:

    • Owner: Read, write, and execute.

    • Group: Read and execute.

    • Others: Execute only.


    如何使用install命令 (How to Use the install Command)

    Our fictional  programmer’s working directory is ~/work. He has written the program, compiled it, and produced a binary called ana. He already created the database file that ana works with, Words.db. So both files are ready for testing. Let’s take a look at them:

    我们虚构的程序员的工作目录是~/work 。 他编写了程序,对其进行了编译,并生成了一个名为ana的二进制文件。 他已经创建了ana可以使用的数据库文件Words.db 。 因此,两个文件都可以进行测试了。 让我们看看它们:

    ls -l ana Words.db

    The ana utility he has just written creates anagrams out of a phrase provided on the command line. Verification testing is quite straightforward.

    他刚刚编写的ana实用程序使用命令行上提供的短语创建了anagram。 验证测试非常简单。

    test of ana utility in work directory

    Our programmer has invoked ana with the phrase “biscuit” and all seems well. He now wants to copy these two files to the ~/test/ana directory to see if the new utility functions correctly away from the development environment. He issues the following command:

    我们的程序员用“饼干”一词调用了ana ,一切似乎都很好。 现在,他想将这两个文件复制到~/test/ana目录中,以查看新实用程序是否在开发环境之外正常工作。 他发出以下命令:

    install -D -v ana Words.db -t ~/test/ana
    Install command to /test/ana

    The options used on the command line were:


    • D: Create directories, including parent directories, if required.

      D :创建目录,包括父目录(如果需要)。

    • v: Verbose, list each directory as it is made and each file copy as it is performed.

      v :详细列出每个目录,并列出每个文件的副本。

    • t: Target directory.

      t :目标目录。

    We can see that install creates the ~/test directory, and then creates the ~/test/ana directory. The files are listed one by one as they are copied to the target directory.

    我们可以看到install创建了~/test目录,然后创建了~/test/ana目录。 这些文件在复制到目标目录时会一一列出。

    Listing the files in ~/test/ana confirms they have been copied over correctly.


    ls -l
    ls in /test/ana directory

    The next step is to test the ana utility by invoking it in the ~/test/ana directory.


    test of ana utility in /test/ana directory

    The utility operates as expected, which is great. However, the permissions are not correct. The requirement is to set members of the group geek to have read and execute permissions, and for other users to have execute only.

    该实用程序按预期运行,这很棒。 但是,权限不正确。 要求是将geek组的成员设置为具有读取和执行权限,而其他用户则仅具有执行权限。

    We can address both of those issues quite simply with the following command. Note  the use of sudo to run the command with root permissions. The -o and -g and options require this. We’ll be asked for our password when we issue the command.

    我们可以使用以下命令非常简单地解决这两个问题。 注意使用sudo以root权限运行命令。 -o-g和选项需要此选项。 发出命令时,系统会要求我们输入密码。

    sudo install -b -S .bak -o dave -g geek -m 751 ana Words.db -t ~/test/ana
    install command with backup options and premissions settings
    • The -b (backup) option creates backups of the files before they are overwritten.

      -b (备份)选项在覆盖文件之前创建文件备份。

    • The -S (suffix) option defines the suffix for the backup files. If you do not provide a suffix a ~ (tilde) is used. We’re asking install to use a suffix of .bak.

      -S (后缀)选项定义备份文件的后缀。 如果不提供后缀,则使用~ (代字号)。 我们要求install使用.bak后缀。

    • We set the owner of the file to be dave using the -o (owner) option.

      我们使用-o (所有者)选项将文件的所有者设置为dave

    • The -g (group) option requires the name of a group. This becomes the owner group of the files. The group we are going to use is called geek.

      -g (组)选项需要一个组的名称。 这将成为文件的所有者组。 我们将要使用的组称为geek

    • The -m (mode) option sets the file modes for the files, using the standard chmod numerical syntax.

      -m (模式)选项使用标准的chmod数字语法设置文件的文件模式。

    We no longer need to use the -D (create directories) option, because we know the test directory already exists. We’ve also omitted the -v (verbose) option. Listing the files in our ~/test/ana directory shows us the file details:

    我们不再需要使用-D (创建目录)选项,因为我们知道测试目录已经存在。 我们还省略了-v (详细)选项。 在~/test/ana目录中列出文件会向我们显示文件详细信息:

    ls -l
    ls in /test/ana directory

    This confirms that all our requirements have been met.


    • The files have been copied across to the testing directory.

    • The permissions have been set correctly.

    • dave is the owner of the files.


    • The geek group is the owner group of the two files.


    • Backup copies have been made of each file, called ana.bak and Words.db.bak.


    All that was achieved through the use of one command. Neat.

    所有这些都是通过使用一个命令来实现的。 整齐。

    Our programmer makes some final changes to the utility and re-compiles. The files that have changed need to be copied over to the ~/test/ana directory from the ~/work directory. We can do this by using the -C (compare) option. If the source file and target file are the same, the source file is not copied.

    我们的程序员对实用程序进行了一些最终更改,然后重新编译。 需要将已更改的文件从~/work目录复制到~/test/ana目录。 我们可以通过使用-C (比较)选项来实现。 如果源文件和目标文件相同,则不会复制源文件。

    sudo install -C -b -S .bak -o dave -g geek -m 751 ana Words.db -t ~/test/ana
    install command with -C compare option

    Listing the files in the target directory shows us that the file size of the ana file has changed. It is bigger than the ana.bakfile. The timestamp on ana has also changed. These changes are because the new version of the file has been copied here.

    列出目标目录中的文件会向我们表明ana文件的文件大小已更改。 它大于ana.bak文件。 ana的时间戳也已更改。 这些更改是因为文件的新版本已在此处复制。

    ls -l
    ls in /test/ana with test fo ana utility

    The file size and timestamp of the Words.db file have not changed. No changes were made to the Words.db file, so it was not copied over. On a project with many files the -C (compare) option can save a lot of time and hard drive churn, by only copying those files that have been changed.

    Words.db文件的文件大小和时间戳未更改。 没有对Words.db文件进行任何更改,因此未将其复制。 在具有许多文件的项目中, -C (比较)选项通过仅复制那些已更改的文件,可以节省大量时间和硬盘驱动器混乱。

    The programmer has again tested that the ana utility continues to operate.


    It is time to use install to copy the files to the /usr/local/bin directory. This will make the new utility available for all users of this Linux computer. We know that /usr/local/bin exists, so we don’t need to create that directory. We can use a modified version of our last command.

    现在该使用install将文件复制到/usr/local/bin目录了。 这将使新实用程序可用于此Linux计算机的所有用户。 我们知道/usr/local/bin存在,所以我们不需要创建该目录。 我们可以使用上一个命令的修改版本。

    We’ve changed the target directory to be /usr/local/bin. We’ve removed the -C (compare) option because there are no copies of these files in the target directory yet, so there is nothing to compare against. Likewise, there is nothing to back up, so we can remove the -b (backup) option and the -S (suffix) option.

    我们将目标目录更改为/usr/local/bin 。 我们删除了-C (比较)选项,因为目标目录中还没有这些文件的副本,因此没有可比较的内容。 同样,没有要备份的内容,因此我们可以删除-b (备份)选项和-S (后缀)选项。

    sudo install -o dave -g geek -m 751 ana Words.db -t /usr/local/bin
    install copying files to /usr/local/bin

    We can list that the files have arrived in /usr/local/bin:


    ls -l
    ls of /usr/local/bin

    And as a final test let’s change directory to our home directory and see if we can invoke our new utility from there.


    test of ana utility

    Note that we didn’t need to preface the ana command with ./  which means it is running from /usr/local/bin. Mission accomplished.

    请注意,我们不需要在ana命令前加上./ ,这意味着它从/usr/local/bin 。 任务完成。

    We mentioned that install can strip out redundant symbol tables and other baggage from within the binary file, to reduce it in size. Let’s do that now. Note that the command below does not include Words.db. This is because Words.db is a database file, not a binary executable. To copy and shrink the binary file ana we can use the following command. We have added the -s (shrink) option with a lower case “s.” We’ve added back in the -b (backup) option and the -S (suffix) option, with an uppercase “S.”

    我们提到安装可以从二进制文件中删除多余的符号表和其他包,以减小其大小。 现在开始吧。 请注意,下面的命令不包括Words.db。 这是因为Words.db是数据库文件,而不是二进制可执行文件。 要复制和收缩的二进制文件ana ,我们可以使用下面的命令。 我们添加了-s(收缩)选项,并使用小写的“ s”。 我们在-b(备份)选项和-S(后缀)选项中重新添加了大写字母“ S”。

    sudo install -s -b -S .bak -o dave -g geek -m 751 ana -t /usr/local/bin
    install option with -s strip option

    Listing the files in /usr/local/bin allows us to compare the size of the ana file with its backup version. The ana file has been reduced to almost 60% of its previous size.

    /usr/local/bin列出文件,使我们可以比较ana文件的大小及其备份版本。 ana文件已减少到其先前大小的近60%。

    ls -l /usr/local/bin
    ls in work directory

    综上所述 (In Summary)

    The the install command caters to a pretty niche use. For many people it won’t be used day in and day out, or possibly from month to month. Despite that, the install command is a good tool to be familiar with and to have in your arsenal of tricks. For those occasions when you need it, it rewards your learning curve with boosts in efficiency, simplicity and simply fewer keystrokes.

    install命令可满足特定用途。 对于许多人来说,它不会日复一日地使用,或者可能逐月使用。 尽管如此, install命令还是一个熟悉和掌握技巧的好工具。 对于那些您需要的场合,它可以通过提高效率,简化操作和减少击键次数来奖励您的学习曲线。

    翻译自: https://www.howtogeek.com/411366/how-to-copy-files-with-the-install-command-on-linux/


  • **linux 系统如何复制文件到当前目录** #*linux 系统如何复制文件到当前目录 首先使用命令函数“cp” 即copy的缩写 如果想把其他目录下的文件复制到当前目录下,则需在当前目录下写如下命令 cp ~/file1 ./ 新的改变...
      **linux 系统如何复制文件到当前目录**

    #*linux 系统如何复制文件到当前目录

    首先使用命令函数“cp” 即copy的缩写
    cp ~/file1 ./

  • Linux 如何快速复制文件

    万次阅读 2019-04-24 09:42:00
    1,在需要对大量小文件进行移动或复制时,用cp、mv都会显得很没有效率,可以用tar先压缩再解压缩的方式。  2,在网络环境中传输时,可以再结合nc命令,通过管道和tcp端口进行传输。  nc和tar可以用来快速的...



     由于nc是一个超轻量的命令,所以一般busybox都会集成它。当一个linux终端,比如linux pda, 
     通过usblan的方式连接到另一台linux主机的时候,这样的嵌入式终端上一般不会集成ftp server, ssh server 
     这样比较笨重的服务,这个时候, nc可能成为唯一的上传手段。 

    比如将机器A上的mytest目录上传到到机器 B(上,只需要: 


    nc -l 6666 |tar -C /target_dir -zxf -


    然后,在A上通过nc和 tar发送test目录。使用一致的6666的端口。 

    tar -zcvf - mytest |nc 6666

    Sometimes a simple cp -a command is a very painful and slow process. It's true that -v (verbose) option can give you some information on the details of the copy process, but not normally the progress of it. In fact, cp -a is a quite slow process that sometimes is faster (and safer) implemented by tar, for example:


    $ tar cf - . | (cd /dst; tar xvf -)


    Usually faster, and more verbose. Another commands such as pv can help you too, to monitor the progress of a copy between two directories, for example:


    $ tar cf - . | pv | (cd /dst; tar xf -)
    2,06GB 0:00:09 [ 194MB/s] [  <=>                     ]


    But copying several gigabytes/terabytes of data and many files between quite old NFS disks is painful via cp. Let's see two alternatives for:

    •  Monitoring the progress of the copy and the copied files.
    •  Skipping to next file before an error (gcp)
    •  Syncing directories (rsync)
    •  Copying files via network (rsync)

    One of the better commands for doing copies is rsync, that allows you to synchronize two directories, and in this sense src/ can have live data, that incrementally is synced to dst/ in several executions of the command


    $ rsync --info=progress2 -auvz ~/Music/ /data/music/


    giving a result like this:


    Jake Bugg - Jake Bugg Album 2012/
    Jake Bugg - Jake Bugg Album 2012/01 - Lighting Bolt.mp3
      1,913,897,967  15%   22.79MB/s    0:01:20 (xfr#277, ir-chk=1019/1825)
    Jake Bugg - Jake Bugg Album 2012/05 - Simple As This.mp3
      1,936,698,070  15%   22.80MB/s    0:01:21 (xfr#281, ir-chk=1015/1825)


    You can also use it with -n option to perform a dry run (this is more used than the skype test call), that checks and lists the differences between the two given directories. You can use it too with "-e ssh" user@host:dst/ or without --info option in older versions of rsync. It is slower for copying but it does a lot of useful things such syncing, checkings md5sums.... You will remember rsync if something goes bad.


    Another fantastic command for copy is gcp. Besides of progress estimation, gcp does not copy when the file exists, skips to the next file if occurs an error, and all the fails are written to a journal file. 


    $ gcp -rv ~/Music/* /data/music/
    Copying 13.53 GiB   2% |#                                  | 165.50 MB/s ETA:  0:01:25


    Please check journal: /home/cesar/.gcp/journal


    $ cat /home/cesar/.gcp/journal
    /home/cesar/Music/Alabama Shakes-Boys & Girls (2014)/01 - Alabama Shakes - Hold On.mp3
    FAILED: already exists
    /home/cesar/Music/Alabama Shakes-Boys & Girls (2014)/03 - Alabama Shakes - Hang Loose.mp3
    FAILED: already exists


    In an Alfresco context, many simple migrations (or restoring processes) are tracked via CIFS or Webdav drives. In these cases the above commands are useful. Even they can be useful, if you are doing a local copy in an Alfresco instance, for performing a later Filesystem Bulk process in Alfresco. From a system administrator point of view, when restoring huge contentstores or Lucene / SOLR indices, or moving backups, these commands can save you so much time.


    Another day we took some time in alternatives for scp copies between two machines.


    Some useful links for reading and just patience for copying:

    NOTE: ~/Music and /data/music are simple tests on a local SSD disk. 


  • 世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。 远程文件复制 scp -P [port] -r [username]@[ip]:[remotedir] [localdir]
  • linux 系统如何复制文件到指定目录

    千次阅读 2019-10-01 20:28:06
    首先使用命令函数“cp” 即copy的缩写, 一般模式: cp filename 路径。 如file1在A目录下,我们想把file1复制到B目录下 命令为 cp file1 /home/B 这个命令包括三...注意:1、命令应在想要复制文件所在的目录下...
  • 从一个服务器复制文件到另一个服务器,或者从本地到远程复制是 Linux 管理员的日常任务之一。-- Prakash Subramanian从一个服务器复制文件到另一个服务...
  • 如何Linux复制文件到多个目录中 编译自:http://www.tecmint.com/copy-file-to-multiple-directories-in-linux/ 作者: Aaron Kili 原创:LCTT https://linux.cn/article-8041-1.html 译者: ...
  • scp root@命令解释:把服务器192.168.3.32上的 soft目录下的linux.x64_11gR2_database_2of2.zip文件拷贝到当前服务器的/soft目录下,回车后需要输入32的机器密码
  • windows,linux如何监听新建文件,复制文件,移动文件,剪切文件,修改文件.zip 监听文件修改事件,文件监控文件的新建,复制,修改,剪切,删除,修改操作 包括两个版本:windows版和linux
  • (1)复制文件 cp -r 要copy的文件/("/"指的是包括里面的内容) newfile_name(要命名的文件名) eg:cp -r webapps_zero/ fxtf (2)删除文件里的内容 rm -rf 要删除的文件内容/(“/”代表的是里面的内容,不能少...
  • 本文主要讲解linux怎么复制文件到其他文件夹。 在Linux和Unix系统上工作时,复制文件和目录是您每天要执行的最常见任务之一。 cp是一个命令行实用程序,用于复制Unix和Linux系统上的文件和目录。在本文中,我们将...
  • 在学习 Linux 的过程中,对于新手而言总是会使用几个命令来完成一个简单的任务。对正在熟悉使用终端的人这是很容易理解的行为。然而,如果你想要成为一个...在 Linux 中,cp 命令常被用于从一个文件夹中复制文件到...
  • Linux 复制文件到当前目录 如何Linux 系统下复制当前目录的文件到当前目录 1)查看当前路径 pwd >>/home/user 2)选择要复制的文件,以及重命名后的文件 比如,我们要复制 /home/user 目录下的 test.sh ...
  • 从一个服务器复制文件到另一个服务器,或者从本地到远程复制是 Linux 管理员的日常任务之一。 我觉得不会有人不同意,因为无论在哪里这都是你的日常操作之一。有很多办法都能处理这个任务,我们试着加以概括。你...
  • Linux 如何使用scp免密登录服务器 scp命令每次上传到服务器都需要密码,所以要做一下配置 这个是从本地复制到服务器上,但是要输入密码 scp ./test root@ 我们需要用ssh来解决这个问题...
  • linux中使用cp命令复制文件的方法:【cp 源文件 目标文件夹】。例如我们要将1.txt文件复制到testDir目录下,可以执行命令【cp 1.txt testDir】。 示例:将1.txt文件分别复制到testDir文件夹下、testDir文件夹的2....
  • 世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序...文件复制: 1. 源文件:old.file 2. 创建一个新文件:touch new.file 3. 复制:mv old.file new.file 4. 提示是否覆盖:y 5. 完成 ...
  • linux操作系统的服务器如何复制文件到另一台linux操作系统的服务器 scp -r 文件名.后缀 ip(你要拷贝到的服务器地址):/目录(你要拷贝到的服务器的目录) 例子: scp -r DCP.bak 后面会让你...
  • linux如何复制文件夹

    2015-09-01 15:39:54
    我想把我的某个目录下的某个文件夹复制(如:/tmp/a,啊是文件夹名称)到某个目录下...格式: CP [选项] 源文件或目录 目的文件或目录 -f 强制覆盖同名文件 -r 按递归方式保留原目录结构复制文件cp -r /tmp/a /root/a
  • Linux如何复制和删除文件夹中的所有文件



1 2 3 4 5 ... 20
收藏数 1,631
精华内容 652


linux 订阅