Corrupted Disciple
Corrupted Disciple

Reputation: 73

How to copy files using wildcards in Unix

How can I copy files to current directory (using wildcards) which names are matches following rules:

  1. start with the word file
  2. after that word have one or more numbers
  3. after the numbers have .txt extension

I tried:

$ cp path_name/file[0-9].txt ./

Here are some examples of the files I want to copy:

file1.txt  
file45.txt  
file5642.txt 

Upvotes: 1

Views: 2605

Answers (1)

selyunin
selyunin

Reputation: 1630

Try this:

cp `find /path/to/files |  grep -E 'file[[:digit:]]+\.txt'` ./

(change /path/to/files to your actual path, change ./ to your destination directory)

Upvotes: 1

Related Questions