How to copy the contents of all files with a certain name into a new file? 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 Results Why I closed the “Why is Kali so hard” questionOptions 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?How do I reassemble randomly named tar file fragments?Background vs foreground task and running tasks in parallelWhy does default setfacl fail for nested directories?Is there a one line command to print the longest line within the files in a directory?Delete file which matches a pattern using linux commandFind all files with the same nameCopy only files with certain extension while renaming each file according to the parent folder

How to compare two different files line by line in unix?

Crossing US/Canada Border for less than 24 hours

Why are the trig functions versine, haversine, exsecant, etc, rarely used in modern mathematics?

8 Prisoners wearing hats

Circuit to "zoom in" on mV fluctuations of a DC signal?

What does the "x" in "x86" represent?

Is "Reachable Object" really an NP-complete problem?

How to convince students of the implication truth values?

How does the math work when buying airline miles?

Is CEO the profession with the most psychopaths?

Do I really need to have a message in a novel to appeal to readers?

Trademark violation for app?

How do I stop a creek from eroding my steep embankment?

What does this Jacques Hadamard quote mean?

Most bit efficient text communication method?

Why didn't Eitri join the fight?

Generate an RGB colour grid

How would a mousetrap for use in space work?

Is safe to use va_start macro with this as parameter?

Can a new player join a group only when a new campaign starts?

Can melee weapons be used to deliver Contact Poisons?

Closed form of recurrent arithmetic series summation

If my PI received research grants from a company to be able to pay my postdoc salary, did I have a potential conflict interest too?

What would be the ideal power source for a cybernetic eye?



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



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 Results
Why I closed the “Why is Kali so hard” questionOptions 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?How do I reassemble randomly named tar file fragments?Background vs foreground task and running tasks in parallelWhy does default setfacl fail for nested directories?Is there a one line command to print the longest line within the files in a directory?Delete file which matches a pattern using linux commandFind all files with the same nameCopy only files with certain extension while renaming each file according to the parent folder



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








2















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, reporting



cat: /: Is a directory


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
    Apr 13 at 17:58











  • All files everywhere

    – Eleuis
    Apr 13 at 18:00

















2















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, reporting



cat: /: Is a directory


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
    Apr 13 at 17:58











  • All files everywhere

    – Eleuis
    Apr 13 at 18:00













2












2








2








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, reporting



cat: /: Is a directory


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, reporting



cat: /: Is a directory


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 Apr 13 at 18:59









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 Apr 13 at 17:36









EleuisEleuis

133




133




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
    Apr 13 at 17:58











  • All files everywhere

    – Eleuis
    Apr 13 at 18:00

















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

    – Jesse_b
    Apr 13 at 17:58











  • All files everywhere

    – Eleuis
    Apr 13 at 18:00
















All files everywhere or all files in a certain directory?

– Jesse_b
Apr 13 at 17:58





All files everywhere or all files in a certain directory?

– Jesse_b
Apr 13 at 17:58













All files everywhere

– Eleuis
Apr 13 at 18:00





All files everywhere

– Eleuis
Apr 13 at 18:00










1 Answer
1






active

oldest

votes


















6














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


















  • 3





    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
    Apr 13 at 18:07











  • It works perfectly, thank you

    – Eleuis
    Apr 13 at 18:08






  • 1





    To accept an answer click the ✓

    – ctrl-alt-delor
    Apr 13 at 18:31






  • 1





    -exec cat + would be more efficient as it would call cat as few times as possible.

    – Kusalananda
    Apr 13 at 19:26











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









6














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


















  • 3





    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
    Apr 13 at 18:07











  • It works perfectly, thank you

    – Eleuis
    Apr 13 at 18:08






  • 1





    To accept an answer click the ✓

    – ctrl-alt-delor
    Apr 13 at 18:31






  • 1





    -exec cat + would be more efficient as it would call cat as few times as possible.

    – Kusalananda
    Apr 13 at 19:26















6














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


















  • 3





    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
    Apr 13 at 18:07











  • It works perfectly, thank you

    – Eleuis
    Apr 13 at 18:08






  • 1





    To accept an answer click the ✓

    – ctrl-alt-delor
    Apr 13 at 18:31






  • 1





    -exec cat + would be more efficient as it would call cat as few times as possible.

    – Kusalananda
    Apr 13 at 19:26













6












6








6







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 Apr 13 at 18:00









FreddyFreddy

1,939210




1,939210







  • 3





    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
    Apr 13 at 18:07











  • It works perfectly, thank you

    – Eleuis
    Apr 13 at 18:08






  • 1





    To accept an answer click the ✓

    – ctrl-alt-delor
    Apr 13 at 18:31






  • 1





    -exec cat + would be more efficient as it would call cat as few times as possible.

    – Kusalananda
    Apr 13 at 19:26












  • 3





    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
    Apr 13 at 18:07











  • It works perfectly, thank you

    – Eleuis
    Apr 13 at 18:08






  • 1





    To accept an answer click the ✓

    – ctrl-alt-delor
    Apr 13 at 18:31






  • 1





    -exec cat + would be more efficient as it would call cat as few times as possible.

    – Kusalananda
    Apr 13 at 19:26







3




3





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
Apr 13 at 18:07





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
Apr 13 at 18:07













It works perfectly, thank you

– Eleuis
Apr 13 at 18:08





It works perfectly, thank you

– Eleuis
Apr 13 at 18:08




1




1





To accept an answer click the ✓

– ctrl-alt-delor
Apr 13 at 18:31





To accept an answer click the ✓

– ctrl-alt-delor
Apr 13 at 18:31




1




1





-exec cat + would be more efficient as it would call cat as few times as possible.

– Kusalananda
Apr 13 at 19:26





-exec cat + would be more efficient as it would call cat as few times as possible.

– Kusalananda
Apr 13 at 19:26










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

getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

Cannot Extend partition with GParted 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 ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.