[英]Linux Move txt files not start with String to Another folder
The situation is情况是
I have a directory A, I have a bunch of files and folders in the foldler.我有一个目录A,文件夹中有一堆文件和文件夹。 Such as folder B , foler C , tmp1.txt , Hello.txt , tmp3.txt , okay.txt.
比如文件夹 B , foler C , tmp1.txt , Hello.txt , tmp3.txt , Ok.txt。
And in folder B,there are also a bunch of files in it.在文件夹B中,还有一堆文件。
So I want to move all txt files recrusively to another folder such as /home.所以我想将所有 txt 文件递归地移动到另一个文件夹,例如 /home。
Here is my code.这是我的代码。
find . -name "*.txt"| grep -v [\s\S]*tmp[\s\S]* -exec mv {} /home \;
I can only select these files,however it won't execute move operation.我只能选择这些文件,但是它不会执行移动操作。
because linux find has path in result.So it annoy me a lot.因为 linux find 有结果路径。所以它让我很恼火。
To move only regular files, add -type f
and exclude the files you don't want with \\!
要仅移动常规文件,请添加
-type f
并使用\\!
: :
find . -type f -name '*.txt' \! -name '*tmp*' -exec mv -i -t /home {} +
The -i
asks for permission to overwrite a file if it already exists and the +
instead of the \\;
如果文件已经存在,则
-i
请求覆盖文件的权限,并且+
而不是\\;
is used to move as many files as possible with one invocation of mv
(and thus we need to specify the target directory with the -t
option as {}
contains more than one file).用于通过一次
mv
调用移动尽可能多的文件(因此我们需要使用-t
选项指定目标目录,因为{}
包含多个文件)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.