Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Linux, how to copy all the files not starting with a given string?

Tags:

regex

linux

unix

cp

I tried with the following command:

cp src_folder/[!String]* dest_folder

However, this command will copy all the files that don't start with any of the characters 'S','t','r','i','n','g' instead of copying files that don't start with "String".

like image 219
mstaniloiu Avatar asked Jan 12 '11 14:01

mstaniloiu


1 Answers

A variation on Konrad answer, using cp option -t to specify target directory simplifies the last command. It creates a single cp process to copy all the files.

ls src_folder | grep -v '^String' | xargs cp -t dest_folder
  • list all files in src_folder
  • filter out all those that start with String
  • copy all remaining files to dest_dir
like image 129
Didier Trosset Avatar answered Oct 04 '22 15:10

Didier Trosset