简体   繁体   English

在bash中列出复制的文件

[英]List copied files in bash

I need to copy files from one directory to another (pretty obvious :) ) but I want to store list of files that were copied with destination path. 我需要将文件从一个目录复制到另一个目录(很明显:)),但是我想存储使用目标路径复制的文件列表。 So let's say I have: /mnt/a/f1 /mnt/a/f2 假设我有:/ mnt / a / f1 / mnt / a / f2

and I want to copy all files from 'a' to root so I do: cp -rv /mnt/a/* / 我想将所有文件从“ a”复制到根目录,所以我要这样做: cp -rv /mnt/a/* /

output from cp I will have will look like: cp的输出将如下所示:

`/mnt/a/f1` -> `/f1`

`/mnt/a/f2` -> `/f2`

and now I want to store in some file list that will looks like: 现在我要存储在一些文件列表中,该文件列表如下所示:

/f1

/f2

Does somebody know how can I achieve such output? 有人知道我如何获得这种输出吗?

cp -rv /mnt/a/* / 2>&1 | cut -d\` -f4 | tee thefile.txt

像这样(未经测试)。

You can simply use something like 您可以简单地使用类似

cp -rv files dest > output_file 

and redirect all the output to a file, but if you absolutely need to split it so you only have the ending I would recommend writing something quickly in Ruby, Python, or Perl and just symlink it as something like "verbose_cp". 并将所有输出重定向到一个文件,但是如果您绝对需要分割它以便只有结尾,那么我建议您使用Ruby,Python或Perl快速编写内容,并将其符号链接为“ verbose_cp”。 If you really want to you can do the splitting in Bash , though in my opinion doing it in languages with stronger string handling would be much easier. 如果您确实愿意,可以使用Bash进行拆分,尽管我认为使用具有更强字符串处理能力的语言进行拆分会容易得多。

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

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