Thursday, March 31, 2011

File extension search and copy

SkyHi @ Thursday, March 31, 2011
find ./ -name "*.txt" -exec cp {} newfolder \;

But need to to find both .txt and .csv files
find ./ -name "*.[ct][sx][vt]" -exec cp {} newfolder \;
This command recursively finds from the current directory and subdirectories, files with names as per the below criteria.

After . the first character must be c or t (For .csv and .txt files)
After . the second character must be s or x (For .csv and .txt files)
After . the third character must be v or t (For .csv and .txt files)

Anyway, other combinations will also match (like .cxt) which I mentioned in my previous reply.

The exec in the above command copies all the found files (i.e, all .csv and .txt files we need) to the directory called newfolder.

ni@Januty:$ find . -iname "*.txt" -mtime -0.1 -exec cp {} ch5 \;