How to copy the contents of all files with a certain name into a new file?
.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, reporting
cat: /: Is a directory
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, reporting
cat: /: Is a directory
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
1 hour ago
All files everywhere
– Eleuis
1 hour 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, reporting
cat: /: Is a directory
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, reporting
cat: /: Is a directory
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 40 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 2 hours 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
1 hour ago
All files everywhere
– Eleuis
1 hour ago
add a comment |
All files everywhere or all files in a certain directory?
– Jesse_b
1 hour ago
All files everywhere
– Eleuis
1 hour ago
All files everywhere or all files in a certain directory?
– Jesse_b
1 hour ago
All files everywhere or all files in a certain directory?
– Jesse_b
1 hour ago
All files everywhere
– Eleuis
1 hour ago
All files everywhere
– Eleuis
1 hour 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
1 hour ago
It works perfectly, thank you
– Eleuis
1 hour ago
1
To accept an answer click the ✓
– ctrl-alt-delor
1 hour ago
-exec cat {} +would be more efficient as it would callcatas few times as possible.
– Kusalananda♦
12 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
1 hour ago
It works perfectly, thank you
– Eleuis
1 hour ago
1
To accept an answer click the ✓
– ctrl-alt-delor
1 hour ago
-exec cat {} +would be more efficient as it would callcatas few times as possible.
– Kusalananda♦
12 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
1 hour ago
It works perfectly, thank you
– Eleuis
1 hour ago
1
To accept an answer click the ✓
– ctrl-alt-delor
1 hour ago
-exec cat {} +would be more efficient as it would callcatas few times as possible.
– Kusalananda♦
12 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 1 hour 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
1 hour ago
It works perfectly, thank you
– Eleuis
1 hour ago
1
To accept an answer click the ✓
– ctrl-alt-delor
1 hour ago
-exec cat {} +would be more efficient as it would callcatas few times as possible.
– Kusalananda♦
12 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
1 hour ago
It works perfectly, thank you
– Eleuis
1 hour ago
1
To accept an answer click the ✓
– ctrl-alt-delor
1 hour ago
-exec cat {} +would be more efficient as it would callcatas few times as possible.
– Kusalananda♦
12 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
1 hour 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
1 hour ago
It works perfectly, thank you
– Eleuis
1 hour ago
It works perfectly, thank you
– Eleuis
1 hour ago
1
1
To accept an answer click the ✓
– ctrl-alt-delor
1 hour ago
To accept an answer click the ✓
– ctrl-alt-delor
1 hour ago
-exec cat {} + would be more efficient as it would call cat as few times as possible.– Kusalananda♦
12 mins ago
-exec cat {} + would be more efficient as it would call cat as few times as possible.– Kusalananda♦
12 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
1 hour ago
All files everywhere
– Eleuis
1 hour ago