简体   繁体   English

Linux将不以字符串开头的txt文件移动到另一个文件夹

[英]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.

相关问题 在Linux中以maxdepth 2查找文件并移至相应的文件夹 - Find files with maxdepth 2 in Linux and move to respective folder linux bash脚本创建文件夹和移动文件 - linux bash script to create folder and move files 在Linux中将以“ a”,“ c”或“ e”开头的前N个文件从一个文件夹复制到另一个文件夹 - Copy first N files which start with 'a' 'c' or 'e' from one folder to another in Linux 根据文件夹的日期和文件的日期将文件移动到linux中各自的文件夹 - Move files to their respective folder in linux based on the date of the folder and the date of the file 将具有特定扩展名的文件符号链接到Linux中的另一个文件夹 - Symlinking files with specific extension into another folder in linux 将每月的linux文件移动到另一个文件夹脚本 - moving monthly linux files to another folder script 如何在 ssh 控制台中将文件夹的所有文件移动到另一个文件夹? - How to move all files of a folder to another folder in ssh console? 如何在Linux中基于父文件夹移动和重命名文件? - How to move and rename files based on parent folder in Linux? 将所有文件夹和文件移动到 Linux 目录中具有相同主题名称的文件夹中 - move all the folders and files to the folder with the same subject name in the directory Linux 如何在Linux中根据名称在具有相应名称的文件夹中移动文件? - How to move files in Linux based on its name in a folder with a corresponding name?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM