How to copy the contents of all files with a certain name into a new file? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsOptions for .hidden files?Local disc copy at 10MB/s! What could be the problem?Is there a robust way to cache contents of usb on local hd?Why does default setfacl fail for nested directories?How can I access my account and files from all computersHow to associate file types on Linux host with Windows applications through VirtualBox?Is there a one line command to print the longest line within the files in a directory?How to add a btrfs raid 1 to an encrypted lvm2 volume group under Solus OS (Linux)?Delete file which matches a pattern using linux commandFind all files with the same name

What aspect of planet Earth must be changed to prevent the industrial revolution?

Why can't devices on different VLANs, but on the same subnet, communicate?

Simulating Exploding Dice

Typeface like Times New Roman but with "tied" percent sign

How can I define good in a religion that claims no moral authority?

Who or what is the being for whom Being is a question for Heidegger?

How to pronounce 1ターン?

What was the last x86 CPU that did not have the x87 floating-point unit built in?

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

Hopping to infinity along a string of digits

Do working physicists consider Newtonian mechanics to be "falsified"?

What force causes entropy to increase?

Is this wall load bearing? Blueprints and photos attached

Can the DM override racial traits?

Mortgage adviser recommends a longer term than necessary combined with overpayments

In horse breeding, what is the female equivalent of putting a horse out "to stud"?

Didn't get enough time to take a Coding Test - what to do now?

Did the new image of black hole confirm the general theory of relativity?

Are my PIs rude or am I just being too sensitive?

Relations between two reciprocal partial derivatives?

Is there a writing software that you can sort scenes like slides in PowerPoint?

Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?

Create an outline of font

Match Roman Numerals



How to copy the contents of all files with a certain name into a new file?



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election ResultsOptions for .hidden files?Local disc copy at 10MB/s! What could be the problem?Is there a robust way to cache contents of usb on local hd?Why does default setfacl fail for nested directories?How can I access my account and files from all computersHow to associate file types on Linux host with Windows applications through VirtualBox?Is there a one line command to print the longest line within the files in a directory?How to add a btrfs raid 1 to an encrypted lvm2 volume group under Solus OS (Linux)?Delete file which matches a pattern using linux commandFind all files with the same name



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















What I want to do is search for all the files whose name meet a certain requirement (starts with 's', followed by either a '1' or a '2' and end with 'sh') and then copy the contents of all those files into a new file, (name ending with .txt).



So far, what I think it should look like is this:



cat / "s[1-2]*sh" >> /home/admin/Desktop/myFile.txt


But it does not work and I'm completely out of ideas. I'm running ubuntu 18.04.1










share|improve this question









New contributor




Eleuis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • All files everywhere or all files in a certain directory?

    – Jesse_b
    48 mins ago











  • All files everywhere

    – Eleuis
    46 mins ago











  • In what way does it not work? What happens?

    – ctrl-alt-delor
    16 mins ago











  • @ctrl-alt-delor: cat: /: Is a directory

    – Jesse_b
    7 mins ago

















1















What I want to do is search for all the files whose name meet a certain requirement (starts with 's', followed by either a '1' or a '2' and end with 'sh') and then copy the contents of all those files into a new file, (name ending with .txt).



So far, what I think it should look like is this:



cat / "s[1-2]*sh" >> /home/admin/Desktop/myFile.txt


But it does not work and I'm completely out of ideas. I'm running ubuntu 18.04.1










share|improve this question









New contributor




Eleuis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • All files everywhere or all files in a certain directory?

    – Jesse_b
    48 mins ago











  • All files everywhere

    – Eleuis
    46 mins ago











  • In what way does it not work? What happens?

    – ctrl-alt-delor
    16 mins ago











  • @ctrl-alt-delor: cat: /: Is a directory

    – Jesse_b
    7 mins ago













1












1








1








What I want to do is search for all the files whose name meet a certain requirement (starts with 's', followed by either a '1' or a '2' and end with 'sh') and then copy the contents of all those files into a new file, (name ending with .txt).



So far, what I think it should look like is this:



cat / "s[1-2]*sh" >> /home/admin/Desktop/myFile.txt


But it does not work and I'm completely out of ideas. I'm running ubuntu 18.04.1










share|improve this question









New contributor




Eleuis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












What I want to do is search for all the files whose name meet a certain requirement (starts with 's', followed by either a '1' or a '2' and end with 'sh') and then copy the contents of all those files into a new file, (name ending with .txt).



So far, what I think it should look like is this:



cat / "s[1-2]*sh" >> /home/admin/Desktop/myFile.txt


But it does not work and I'm completely out of ideas. I'm running ubuntu 18.04.1







linux






share|improve this question









New contributor




Eleuis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Eleuis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 16 mins ago









ctrl-alt-delor

12.5k52662




12.5k52662






New contributor




Eleuis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









EleuisEleuis

61




61




New contributor




Eleuis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Eleuis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Eleuis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • All files everywhere or all files in a certain directory?

    – Jesse_b
    48 mins ago











  • All files everywhere

    – Eleuis
    46 mins ago











  • In what way does it not work? What happens?

    – ctrl-alt-delor
    16 mins ago











  • @ctrl-alt-delor: cat: /: Is a directory

    – Jesse_b
    7 mins ago

















  • All files everywhere or all files in a certain directory?

    – Jesse_b
    48 mins ago











  • All files everywhere

    – Eleuis
    46 mins ago











  • In what way does it not work? What happens?

    – ctrl-alt-delor
    16 mins ago











  • @ctrl-alt-delor: cat: /: Is a directory

    – Jesse_b
    7 mins ago
















All files everywhere or all files in a certain directory?

– Jesse_b
48 mins ago





All files everywhere or all files in a certain directory?

– Jesse_b
48 mins ago













All files everywhere

– Eleuis
46 mins ago





All files everywhere

– Eleuis
46 mins ago













In what way does it not work? What happens?

– ctrl-alt-delor
16 mins ago





In what way does it not work? What happens?

– ctrl-alt-delor
16 mins ago













@ctrl-alt-delor: cat: /: Is a directory

– Jesse_b
7 mins ago





@ctrl-alt-delor: cat: /: Is a directory

– Jesse_b
7 mins ago










1 Answer
1






active

oldest

votes


















3














To concatenate the files in your current directory:



cat s[12]*sh > /home/admin/Desktop/myFile.txt


To find and concatenate the files in your current directory and subdirectories:



find . -name "s[12]*sh" -exec cat '' > /home/admin/Desktop/myFile.txt ;


To find and concatenate the files everywhere:



find / -name "s[12]*sh" -exec cat '' > /home/admin/Desktop/myFile.txt ;





share|improve this answer


















  • 2





    note that find -exec cat > out.txt ; is exactly equivalent to find -exec cat ; > out.txt as the shell processes the redirection before find runs, and it applies to the whole find process. So you might as well put the ; before the redirection for clarity. Also, you can use -exec cat + to have find pass more than one file name to each cat invocation. The effect is the same, but it can be faster for large numbers of files.

    – ilkkachu
    39 mins ago











  • It works perfectly, thank you

    – Eleuis
    38 mins ago











  • To accept an answer click the ✓

    – ctrl-alt-delor
    15 mins ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Eleuis is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f512307%2fhow-to-copy-the-contents-of-all-files-with-a-certain-name-into-a-new-file%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














To concatenate the files in your current directory:



cat s[12]*sh > /home/admin/Desktop/myFile.txt


To find and concatenate the files in your current directory and subdirectories:



find . -name "s[12]*sh" -exec cat '' > /home/admin/Desktop/myFile.txt ;


To find and concatenate the files everywhere:



find / -name "s[12]*sh" -exec cat '' > /home/admin/Desktop/myFile.txt ;





share|improve this answer


















  • 2





    note that find -exec cat > out.txt ; is exactly equivalent to find -exec cat ; > out.txt as the shell processes the redirection before find runs, and it applies to the whole find process. So you might as well put the ; before the redirection for clarity. Also, you can use -exec cat + to have find pass more than one file name to each cat invocation. The effect is the same, but it can be faster for large numbers of files.

    – ilkkachu
    39 mins ago











  • It works perfectly, thank you

    – Eleuis
    38 mins ago











  • To accept an answer click the ✓

    – ctrl-alt-delor
    15 mins ago















3














To concatenate the files in your current directory:



cat s[12]*sh > /home/admin/Desktop/myFile.txt


To find and concatenate the files in your current directory and subdirectories:



find . -name "s[12]*sh" -exec cat '' > /home/admin/Desktop/myFile.txt ;


To find and concatenate the files everywhere:



find / -name "s[12]*sh" -exec cat '' > /home/admin/Desktop/myFile.txt ;





share|improve this answer


















  • 2





    note that find -exec cat > out.txt ; is exactly equivalent to find -exec cat ; > out.txt as the shell processes the redirection before find runs, and it applies to the whole find process. So you might as well put the ; before the redirection for clarity. Also, you can use -exec cat + to have find pass more than one file name to each cat invocation. The effect is the same, but it can be faster for large numbers of files.

    – ilkkachu
    39 mins ago











  • It works perfectly, thank you

    – Eleuis
    38 mins ago











  • To accept an answer click the ✓

    – ctrl-alt-delor
    15 mins ago













3












3








3







To concatenate the files in your current directory:



cat s[12]*sh > /home/admin/Desktop/myFile.txt


To find and concatenate the files in your current directory and subdirectories:



find . -name "s[12]*sh" -exec cat '' > /home/admin/Desktop/myFile.txt ;


To find and concatenate the files everywhere:



find / -name "s[12]*sh" -exec cat '' > /home/admin/Desktop/myFile.txt ;





share|improve this answer













To concatenate the files in your current directory:



cat s[12]*sh > /home/admin/Desktop/myFile.txt


To find and concatenate the files in your current directory and subdirectories:



find . -name "s[12]*sh" -exec cat '' > /home/admin/Desktop/myFile.txt ;


To find and concatenate the files everywhere:



find / -name "s[12]*sh" -exec cat '' > /home/admin/Desktop/myFile.txt ;






share|improve this answer












share|improve this answer



share|improve this answer










answered 45 mins ago









FreddyFreddy

1,727210




1,727210







  • 2





    note that find -exec cat > out.txt ; is exactly equivalent to find -exec cat ; > out.txt as the shell processes the redirection before find runs, and it applies to the whole find process. So you might as well put the ; before the redirection for clarity. Also, you can use -exec cat + to have find pass more than one file name to each cat invocation. The effect is the same, but it can be faster for large numbers of files.

    – ilkkachu
    39 mins ago











  • It works perfectly, thank you

    – Eleuis
    38 mins ago











  • To accept an answer click the ✓

    – ctrl-alt-delor
    15 mins ago












  • 2





    note that find -exec cat > out.txt ; is exactly equivalent to find -exec cat ; > out.txt as the shell processes the redirection before find runs, and it applies to the whole find process. So you might as well put the ; before the redirection for clarity. Also, you can use -exec cat + to have find pass more than one file name to each cat invocation. The effect is the same, but it can be faster for large numbers of files.

    – ilkkachu
    39 mins ago











  • It works perfectly, thank you

    – Eleuis
    38 mins ago











  • To accept an answer click the ✓

    – ctrl-alt-delor
    15 mins ago







2




2





note that find -exec cat > out.txt ; is exactly equivalent to find -exec cat ; > out.txt as the shell processes the redirection before find runs, and it applies to the whole find process. So you might as well put the ; before the redirection for clarity. Also, you can use -exec cat + to have find pass more than one file name to each cat invocation. The effect is the same, but it can be faster for large numbers of files.

– ilkkachu
39 mins ago





note that find -exec cat > out.txt ; is exactly equivalent to find -exec cat ; > out.txt as the shell processes the redirection before find runs, and it applies to the whole find process. So you might as well put the ; before the redirection for clarity. Also, you can use -exec cat + to have find pass more than one file name to each cat invocation. The effect is the same, but it can be faster for large numbers of files.

– ilkkachu
39 mins ago













It works perfectly, thank you

– Eleuis
38 mins ago





It works perfectly, thank you

– Eleuis
38 mins ago













To accept an answer click the ✓

– ctrl-alt-delor
15 mins ago





To accept an answer click the ✓

– ctrl-alt-delor
15 mins ago










Eleuis is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















Eleuis is a new contributor. Be nice, and check out our Code of Conduct.












Eleuis is a new contributor. Be nice, and check out our Code of Conduct.











Eleuis is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f512307%2fhow-to-copy-the-contents-of-all-files-with-a-certain-name-into-a-new-file%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Era Viking Índice Início da Era Viquingue | Cotidiano | Sociedade | Língua | Religião | A arte | As primeiras cidades | As viagens dos viquingues | Viquingues do Oeste e Leste | Fim da Era Viquingue | Fontes históricas | Referências Bibliografia | Ligações externas | Menu de navegação«Sverige då!»«Handel I vikingetid»«O que é Nórdico Antigo»Mito, magia e religião na volsunga saga Um olhar sobre a trajetória mítica do herói sigurd«Bonden var den verklige vikingen»«Vikingatiden»«Vikingatiden»«Vinland»«Guerreiras de Óðinn: As Valkyrjor na Mitologia Viking»1519-9053«Esculpindo símbolos e seres: A arte viking em pedras rúnicas»1679-9313Historia - Tema: VikingarnaAventura e Magia no Mundo das Sagas IslandesasEra Vikinge

What's the metal clinking sound at the end of credits in Avengers: Endgame?What makes Thanos so strong in Avengers: Endgame?Who is the character that appears at the end of Endgame?What happens to Mjolnir (Thor's hammer) at the end of Endgame?The People's Ages in Avengers: EndgameWhat did Nebula do in Avengers: Endgame?Messing with time in the Avengers: Endgame climaxAvengers: Endgame timelineWhat are the time-travel rules in Avengers Endgame?Why use this song in Avengers: Endgame Opening Logo Sequence?Peggy's age in Avengers Endgame

Are there legal definitions of ethnicities/races? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Legal definitions in the United StatesAre there truly legal limits on US interest rates?Are gender identity and sexual orientation federally protected?Why is there an apparent legal bias against digital services?What limits are there to the powers of individual judges in the United States legal system?Are women only scholarships legal under Irish / EU law?Is the term “race” defined by Public Law enacted by Congress of the United StatesIs there a legal definition of race in the US?Neighbors are spying for landlord on Renters is it legal?Are Protected Classes Bi-directional?