简体   繁体   中英

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. How can this by achieved?**

I can use *.krn to access every file.

$ 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 --

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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