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?

8
  • How do you define a text file? By having it only contain a set of characters? In whichever case, you may find this useful - stackoverflow.com/a/13659891/3721256 Commented Nov 22, 2017 at 22:40
  • I am defining a text file by having the suffix .txt Commented Nov 22, 2017 at 22:41
  • So *MEDIUM*.txt ? Commented Nov 22, 2017 at 23:01
  • When you say "files containing a string", do you mean the file name contains the string, or the file contents? Commented Nov 22, 2017 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. Commented Nov 22, 2017 at 23:03

1 Answer 1

1
find . -type f | grep MEDIUM | grep '\.txt$' | xargs -I{} mv {} MEDIUM_files 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.