sil*_*npi 103 linux command-line mv
考虑:
ls -al ../public-back
drwxrwxr-x 4 apache apache 4096 Apr 19 03:32 templates
ls -al ../public-back/templates
drwxrwxr-x 2 apache apache 4096 Apr 19 03:33 content
drwxrwxr-x 2 apache apache 20480 Apr 20 06:14 images
drwxrwxr-x 2 apache apache 4096 Apr 19 03:35 video
ls -al /public
drwxrwxr-x 4 apache apache 4096 Apr 20 09:49 templates
ls -al /public/templates
drwxrwxr-x 2 apache apache 4096 Apr 20 09:50 content
drwxrwxr-x 2 apache apache 4096 Apr 20 09:50 images
drwxrwxr-x 2 apache apache 4096 Apr 20 09:50 video
Run Code Online (Sandbox Code Playgroud)
如何将/public-back/templates具有权限的内容递归移动到/public/templates?
DQd*_*dlM 127
除非我误解了这个问题,否则这会起作用:
mv /public-back/templates/* /public/templates
Run Code Online (Sandbox Code Playgroud)
此外,除非您有大量文件,-i否则在覆盖任何内容之前添加会询问,这在使用通配符时增加了一些安全性,例如*.
Him*_*lay 17
cp 的手册页指出:
-p same as --preserve=mode,ownership,timestamps
-r same as --recursive=copy directories recursively
Run Code Online (Sandbox Code Playgroud)
尝试;
cp -rp /public-back/templates/* /public/templates/
Run Code Online (Sandbox Code Playgroud)
rsync通过使用参数可以移动而不是复制--remove-source-files。这将保留权限和修改日期等属性。它的另一个好处是检查文件是否不需要移动到目标目录(即,那里是否已存在同名的新文件)。
rsync -arctuxz --remove-source-files /public-back/templates /public/templates/
Run Code Online (Sandbox Code Playgroud)
当然你也可以复制文件并删除原来的目录。
mkdir -p /public/templates
rsync -arctuxz --remove-source-files /public-back/templates /public/templates/
rm -rfi /public-back/templates/
Run Code Online (Sandbox Code Playgroud)
这是我推荐的参数,rsync但还有其他参数用于保留各种属性或处理链接以及大文件的压缩/加密。此命令还支持通过 ssh 隧道复制到远程文件系统。
将项目从我的拇指驱动器移动到我的 OSMC 系统时,我发现以下内容非常有用:
find /media/Pi\ Hard\ 16GB/ -name '*' -exec mv -v {} /media/External\ HDD/Videos/ \;
Run Code Online (Sandbox Code Playgroud)
下面解释它是如何工作的。
顺便说一句,不要忘记在源或目标目录名称中的任何空格之前添加反斜杠(见上文)。
find finds all files and folders in the destination path.
/media/Pi Hard 16GB/ is the path searched. Escape special char such as spaces.
-name '*' filters on names. If you do not escape or quote this then
the shell will expand it before find sees it.
-exec Executes a command, in our case mv
-v Verbose, so you can see what's happening (optional)
{} is replaced by the name of the found object.
Run Code Online (Sandbox Code Playgroud)
实际上,您正在查找所有文件和所有文件夹并一个一个移动它们(或者如果首先找到一个目录,您正在移动该目录及其中的内容)。这会为每次移动启动一个新流程,并且非常低效。只有在常规命令失败时才使用它。
小智 5
mv好像没有这么做。但你可以使用这个小技巧,效果就像一个魅力:
tar cf - . |(cd /targetdir; tar xvf -)
Run Code Online (Sandbox Code Playgroud)
并保留权限等。
注意:以上方法都不适合我,这就是这个解决方法的原因。
| 归档时间: |
|
| 查看次数: |
414774 次 |
| 最近记录: |