cancel
Showing results for 
Search instead for 
Did you mean: 
dkcbk
Flight Engineer
Flight Engineer
  • 1,807 Views

Command to copy all .yaml and .yml files

Hi.
Is it possible to copy all .yaml and .yml files with one command? Something like $ cp *.y[a]ml /some/dir

Thank you
5 Replies
shashi01
Moderator
Moderator
  • 1,798 Views

Hello @dkcbk 

Thank you for reaching out

You can verify this by using the following command  >>   cp *.yaml *.yml /some/dir

Add  >> cp *.{yml,yaml} /some/dir

0 Kudos
Chetan_Tiwary_
Community Manager
Community Manager
  • 1,788 Views

Hello @dkcbk !

This : $ cp *.y[a]ml /some/dir  will not copy the .yml files because it will expect "a" in the extension. 

Try this and you can copy all the files having similar extensions like .jpeg or .jpg  , .yaml or .yml or likewise :

Screenshot from 2023-09-16 01-30-10.png

0 Kudos
Tracy_Baker
Starfighter Starfighter
Starfighter
  • 1,773 Views

Actually, this will work just fine, because star matches 0 to any number of characters (this also assumes no other files, such as *.yxml, exist):

cp *.y*ml /some/dir

example:

Tracy_Baker_0-1694813040237.png

 

Program Lead at Arizona's first Red Hat Academy, est. 2005
Estrella Mountain Community College
0 Kudos
Travis
Moderator
Moderator
  • 1,765 Views

cp *.yml *.yaml /tmp

Other answers here give you the same thing, but the copy command is capable of copying multiple files, when you have a list of multiple files or file types, the last argument on the line is the directly location where you want to copy the files.

The answer @Tracy_Baker gave you is good too, but as he mentioned it will get other files if they happen to exist. The command above gives you just yml and yaml extenstions and won't get any other files.

Travis Michette, RHCA XIII
https://rhtapps.redhat.com/verify?certId=111-134-086
SENIOR TECHNICAL INSTRUCTOR / CERTIFIED INSTRUCTOR AND EXAMINER
Red Hat Certification + Training
0 Kudos
dkcbk
Flight Engineer
Flight Engineer
  • 1,743 Views

Thank you all.
I know that copy command is capable of copying multiple files. I was curious if it is possible in any other way, with regular expressions.
0 Kudos
Join the discussion
You must log in to join this conversation.