0

I want to collect and move all text files that contain the string “MEDIUM” that are present in my subdirectories on a linux system, to a new folder called MEDIUM_files. I am able to collect all files containing MEDIUM by using

ls *MEDIUM*

but I only want the text files.

All the files contain MEDIUM, but they also differ in number. For example the file name contain different numbers at the end such as "MEDIUM_30_1.txt" or through "MEDIUM_1850_20.txt"

How can I specify a file type as well as containing a string?

Emma
  • 443
  • 2
  • 5
  • 13
  • How do you define a text file? By having it only contain a set of characters? In whichever case, you may find this useful - https://stackoverflow.com/a/13659891/3721256 – Paedolos Nov 22 '17 at 22:40
  • I am defining a text file by having the suffix .txt – Emma Nov 22 '17 at 22:41
  • So `*MEDIUM*.txt` ? – Barmar Nov 22 '17 at 23:01
  • When you say "files containing a string", do you mean the file **name** contains the string, or the file **contents**? – Barmar Nov 22 '17 at 23:02
  • 1
    SO is for programming questions, not questions about using or configuring Linux. SuperUser.com or unix.stackexchange.com would be better places for questions like this. – Barmar Nov 22 '17 at 23:03
  • And if the filename always starts with `MEDIUM`, it should be `MEDIUM*.txt` – Barmar Nov 22 '17 at 23:03
  • Ok, thanks. I hadn't heard of SuperUser, I will post my question there. – Emma Nov 23 '17 at 00:31
  • Possible duplicate of [Linux command: How to 'find' only text files?](https://stackoverflow.com/questions/4767396/linux-command-how-to-find-only-text-files) – tripleee Nov 23 '17 at 06:11

1 Answers1

1
find . -type f | grep MEDIUM | grep '\.txt$' | xargs -I{} mv {} MEDIUM_files
wilsotc
  • 800
  • 4
  • 10