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;
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
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.
add a comment |
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
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
add a comment |
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
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
linux
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.
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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 ;
2
note thatfind -exec cat > out.txt ;is exactly equivalent tofind -exec cat ; > out.txtas the shell processes the redirection beforefindruns, and it applies to the wholefindprocess. So you might as well put the;before the redirection for clarity. Also, you can use-exec cat +to havefindpass more than one file name to eachcatinvocation. 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 ;
2
note thatfind -exec cat > out.txt ;is exactly equivalent tofind -exec cat ; > out.txtas the shell processes the redirection beforefindruns, and it applies to the wholefindprocess. So you might as well put the;before the redirection for clarity. Also, you can use-exec cat +to havefindpass more than one file name to eachcatinvocation. 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
add a comment |
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 ;
2
note thatfind -exec cat > out.txt ;is exactly equivalent tofind -exec cat ; > out.txtas the shell processes the redirection beforefindruns, and it applies to the wholefindprocess. So you might as well put the;before the redirection for clarity. Also, you can use-exec cat +to havefindpass more than one file name to eachcatinvocation. 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
add a comment |
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 ;
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 ;
answered 45 mins ago
FreddyFreddy
1,727210
1,727210
2
note thatfind -exec cat > out.txt ;is exactly equivalent tofind -exec cat ; > out.txtas the shell processes the redirection beforefindruns, and it applies to the wholefindprocess. So you might as well put the;before the redirection for clarity. Also, you can use-exec cat +to havefindpass more than one file name to eachcatinvocation. 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
add a comment |
2
note thatfind -exec cat > out.txt ;is exactly equivalent tofind -exec cat ; > out.txtas the shell processes the redirection beforefindruns, and it applies to the wholefindprocess. So you might as well put the;before the redirection for clarity. Also, you can use-exec cat +to havefindpass more than one file name to eachcatinvocation. 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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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