[英]Sorting files based on content using command line
I have a database of files in a folder. 我在一个文件夹中有一个文件数据库。 I wish to sort the files containing
*C:
into one folder and the files containing *c:
into another folder. 我希望将包含
*C:
的文件排序到一个文件夹中,并将包含*c:
的文件排序到另一个文件夹中。 How can this by achieved?** 如何做到这一点?**
I can use *.krn
to access every file. 我可以使用
*.krn
访问每个文件。
$ grep --help | grep with-matches
-l, --files-with-matches print only names of FILEs containing matches
What now depends on how many files there are and how paranoid you must be about their names. 现在的情况取决于有多少个文件,以及您对它们的名称有多偏执。 From the simplest
从最简单的
mv $(grep -l pattern files) target
to the most robust 到最坚固
grep -l -Z pattern files | xargs -0 mv -t target-directory --
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.