How to redirect all the content of one file to another file?

Clash Royale CLAN TAG#URR8PPP
up vote
-4
down vote
favorite
I have two files: file_a and file_b. I want to redirect (>) all content of file_a into file_b.
pseudo code is file_a > file_b. how to do that? I feel I should use cat.
io-redirection
add a comment |Â
up vote
-4
down vote
favorite
I have two files: file_a and file_b. I want to redirect (>) all content of file_a into file_b.
pseudo code is file_a > file_b. how to do that? I feel I should use cat.
io-redirection
cat file_a > file_b
â RomanPerekhrest
Feb 1 at 14:53
2
@RomanPerekhrest pleaes make that an answer. Trivial though it is.
â roaima
Feb 1 at 14:53
2
@roaima, I can't: it's too primitive and not imposing ...
â RomanPerekhrest
Feb 1 at 14:54
@roaima It's only "trivial" if you disregard what's going on ;-) (what's opening what file and what's happening to permissions etc. in various cases)
â Kusalananda
Feb 1 at 15:42
@Kusalananda at the level the OP is asking the simple form of the answer is trivial ("How do you get a directory listing? -ls"), although I accept that if you have zero knowledge nothing is really trivial. I like your answer because it gives a solution at the simplest possible level, but then goes on to explain for other readers some of the extras that might be relelvant.
â roaima
Feb 1 at 19:50
add a comment |Â
up vote
-4
down vote
favorite
up vote
-4
down vote
favorite
I have two files: file_a and file_b. I want to redirect (>) all content of file_a into file_b.
pseudo code is file_a > file_b. how to do that? I feel I should use cat.
io-redirection
I have two files: file_a and file_b. I want to redirect (>) all content of file_a into file_b.
pseudo code is file_a > file_b. how to do that? I feel I should use cat.
io-redirection
asked Feb 1 at 14:51
redirector
61
61
cat file_a > file_b
â RomanPerekhrest
Feb 1 at 14:53
2
@RomanPerekhrest pleaes make that an answer. Trivial though it is.
â roaima
Feb 1 at 14:53
2
@roaima, I can't: it's too primitive and not imposing ...
â RomanPerekhrest
Feb 1 at 14:54
@roaima It's only "trivial" if you disregard what's going on ;-) (what's opening what file and what's happening to permissions etc. in various cases)
â Kusalananda
Feb 1 at 15:42
@Kusalananda at the level the OP is asking the simple form of the answer is trivial ("How do you get a directory listing? -ls"), although I accept that if you have zero knowledge nothing is really trivial. I like your answer because it gives a solution at the simplest possible level, but then goes on to explain for other readers some of the extras that might be relelvant.
â roaima
Feb 1 at 19:50
add a comment |Â
cat file_a > file_b
â RomanPerekhrest
Feb 1 at 14:53
2
@RomanPerekhrest pleaes make that an answer. Trivial though it is.
â roaima
Feb 1 at 14:53
2
@roaima, I can't: it's too primitive and not imposing ...
â RomanPerekhrest
Feb 1 at 14:54
@roaima It's only "trivial" if you disregard what's going on ;-) (what's opening what file and what's happening to permissions etc. in various cases)
â Kusalananda
Feb 1 at 15:42
@Kusalananda at the level the OP is asking the simple form of the answer is trivial ("How do you get a directory listing? -ls"), although I accept that if you have zero knowledge nothing is really trivial. I like your answer because it gives a solution at the simplest possible level, but then goes on to explain for other readers some of the extras that might be relelvant.
â roaima
Feb 1 at 19:50
cat file_a > file_bâ RomanPerekhrest
Feb 1 at 14:53
cat file_a > file_bâ RomanPerekhrest
Feb 1 at 14:53
2
2
@RomanPerekhrest pleaes make that an answer. Trivial though it is.
â roaima
Feb 1 at 14:53
@RomanPerekhrest pleaes make that an answer. Trivial though it is.
â roaima
Feb 1 at 14:53
2
2
@roaima, I can't: it's too primitive and not imposing ...
â RomanPerekhrest
Feb 1 at 14:54
@roaima, I can't: it's too primitive and not imposing ...
â RomanPerekhrest
Feb 1 at 14:54
@roaima It's only "trivial" if you disregard what's going on ;-) (what's opening what file and what's happening to permissions etc. in various cases)
â Kusalananda
Feb 1 at 15:42
@roaima It's only "trivial" if you disregard what's going on ;-) (what's opening what file and what's happening to permissions etc. in various cases)
â Kusalananda
Feb 1 at 15:42
@Kusalananda at the level the OP is asking the simple form of the answer is trivial ("How do you get a directory listing? -
ls"), although I accept that if you have zero knowledge nothing is really trivial. I like your answer because it gives a solution at the simplest possible level, but then goes on to explain for other readers some of the extras that might be relelvant.â roaima
Feb 1 at 19:50
@Kusalananda at the level the OP is asking the simple form of the answer is trivial ("How do you get a directory listing? -
ls"), although I accept that if you have zero knowledge nothing is really trivial. I like your answer because it gives a solution at the simplest possible level, but then goes on to explain for other readers some of the extras that might be relelvant.â roaima
Feb 1 at 19:50
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
8
down vote
accepted
Nitpick: In Unix, you can redirect output or input streams, but you can't redirect files.
As RomanPerekhrest suggested in comments to the question:
cat file_a >file_b
This redirects the standard output stream (or just "the output") of cat into file_b. The output of cat will be the contents of file_a.
This has the same effect (disregarding edge-case differences regarding permissions and ownership) as
cp file_a file_b
There are many other ways of duplicating a file's complete contents into another file, including trivial examples that apply non-modifying filters on text files, such as
dd if=file_a of=file_b
awk '1' file_a >file_b
sed '' file_a >file_b
etc.
All the above examples will overwrite the previous contents of file_b.
To append to file_b, replace > in the examples above that uses > with >>, e.g.
cat file_a >>file_b
To append the contents of file_a to that of file_b and store that in a third file:
cat file_b file_a >file_c
cat will output the contents of each of its file arguments after each other, in order, and the result will be redirected into the new file_c file.
1
Depending on the implementation, thesed/awkones may not work for non-text files. Theawkone would add back a missing trailing newline character (sedas well with some implementations, some others would remove the unterminated line)
â Stéphane Chazelas
Feb 1 at 15:48
@StéphaneChazelas Yes. I've changed my wording to be slightly more careful.
â Kusalananda
Feb 1 at 15:52
1
I think what would make your nitpick even better is to say that you can redirect standard streams, or perhaps file descriptors in general. "Output of a program" can be arguably stretched as a term.
â Sergiy Kolodyazhnyy
Feb 1 at 16:47
add a comment |Â
up vote
0
down vote
simple way is to copy:
cp file1 file2
there are multiple ways to divert the flow of output data into another file as well e.g.:
cat file1 > file2
less file1 > file2
more file1 > file2
You can use rsync to take backup:
rsync -r /media/hdd1/Folder1/ /media/hdd2/Folder2/
rsync is backing up whole folder from one drive to another and -r option specifies to do it recursively for all files and subfolders.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
Nitpick: In Unix, you can redirect output or input streams, but you can't redirect files.
As RomanPerekhrest suggested in comments to the question:
cat file_a >file_b
This redirects the standard output stream (or just "the output") of cat into file_b. The output of cat will be the contents of file_a.
This has the same effect (disregarding edge-case differences regarding permissions and ownership) as
cp file_a file_b
There are many other ways of duplicating a file's complete contents into another file, including trivial examples that apply non-modifying filters on text files, such as
dd if=file_a of=file_b
awk '1' file_a >file_b
sed '' file_a >file_b
etc.
All the above examples will overwrite the previous contents of file_b.
To append to file_b, replace > in the examples above that uses > with >>, e.g.
cat file_a >>file_b
To append the contents of file_a to that of file_b and store that in a third file:
cat file_b file_a >file_c
cat will output the contents of each of its file arguments after each other, in order, and the result will be redirected into the new file_c file.
1
Depending on the implementation, thesed/awkones may not work for non-text files. Theawkone would add back a missing trailing newline character (sedas well with some implementations, some others would remove the unterminated line)
â Stéphane Chazelas
Feb 1 at 15:48
@StéphaneChazelas Yes. I've changed my wording to be slightly more careful.
â Kusalananda
Feb 1 at 15:52
1
I think what would make your nitpick even better is to say that you can redirect standard streams, or perhaps file descriptors in general. "Output of a program" can be arguably stretched as a term.
â Sergiy Kolodyazhnyy
Feb 1 at 16:47
add a comment |Â
up vote
8
down vote
accepted
Nitpick: In Unix, you can redirect output or input streams, but you can't redirect files.
As RomanPerekhrest suggested in comments to the question:
cat file_a >file_b
This redirects the standard output stream (or just "the output") of cat into file_b. The output of cat will be the contents of file_a.
This has the same effect (disregarding edge-case differences regarding permissions and ownership) as
cp file_a file_b
There are many other ways of duplicating a file's complete contents into another file, including trivial examples that apply non-modifying filters on text files, such as
dd if=file_a of=file_b
awk '1' file_a >file_b
sed '' file_a >file_b
etc.
All the above examples will overwrite the previous contents of file_b.
To append to file_b, replace > in the examples above that uses > with >>, e.g.
cat file_a >>file_b
To append the contents of file_a to that of file_b and store that in a third file:
cat file_b file_a >file_c
cat will output the contents of each of its file arguments after each other, in order, and the result will be redirected into the new file_c file.
1
Depending on the implementation, thesed/awkones may not work for non-text files. Theawkone would add back a missing trailing newline character (sedas well with some implementations, some others would remove the unterminated line)
â Stéphane Chazelas
Feb 1 at 15:48
@StéphaneChazelas Yes. I've changed my wording to be slightly more careful.
â Kusalananda
Feb 1 at 15:52
1
I think what would make your nitpick even better is to say that you can redirect standard streams, or perhaps file descriptors in general. "Output of a program" can be arguably stretched as a term.
â Sergiy Kolodyazhnyy
Feb 1 at 16:47
add a comment |Â
up vote
8
down vote
accepted
up vote
8
down vote
accepted
Nitpick: In Unix, you can redirect output or input streams, but you can't redirect files.
As RomanPerekhrest suggested in comments to the question:
cat file_a >file_b
This redirects the standard output stream (or just "the output") of cat into file_b. The output of cat will be the contents of file_a.
This has the same effect (disregarding edge-case differences regarding permissions and ownership) as
cp file_a file_b
There are many other ways of duplicating a file's complete contents into another file, including trivial examples that apply non-modifying filters on text files, such as
dd if=file_a of=file_b
awk '1' file_a >file_b
sed '' file_a >file_b
etc.
All the above examples will overwrite the previous contents of file_b.
To append to file_b, replace > in the examples above that uses > with >>, e.g.
cat file_a >>file_b
To append the contents of file_a to that of file_b and store that in a third file:
cat file_b file_a >file_c
cat will output the contents of each of its file arguments after each other, in order, and the result will be redirected into the new file_c file.
Nitpick: In Unix, you can redirect output or input streams, but you can't redirect files.
As RomanPerekhrest suggested in comments to the question:
cat file_a >file_b
This redirects the standard output stream (or just "the output") of cat into file_b. The output of cat will be the contents of file_a.
This has the same effect (disregarding edge-case differences regarding permissions and ownership) as
cp file_a file_b
There are many other ways of duplicating a file's complete contents into another file, including trivial examples that apply non-modifying filters on text files, such as
dd if=file_a of=file_b
awk '1' file_a >file_b
sed '' file_a >file_b
etc.
All the above examples will overwrite the previous contents of file_b.
To append to file_b, replace > in the examples above that uses > with >>, e.g.
cat file_a >>file_b
To append the contents of file_a to that of file_b and store that in a third file:
cat file_b file_a >file_c
cat will output the contents of each of its file arguments after each other, in order, and the result will be redirected into the new file_c file.
edited Feb 1 at 16:51
answered Feb 1 at 14:54
Kusalananda
103k13202318
103k13202318
1
Depending on the implementation, thesed/awkones may not work for non-text files. Theawkone would add back a missing trailing newline character (sedas well with some implementations, some others would remove the unterminated line)
â Stéphane Chazelas
Feb 1 at 15:48
@StéphaneChazelas Yes. I've changed my wording to be slightly more careful.
â Kusalananda
Feb 1 at 15:52
1
I think what would make your nitpick even better is to say that you can redirect standard streams, or perhaps file descriptors in general. "Output of a program" can be arguably stretched as a term.
â Sergiy Kolodyazhnyy
Feb 1 at 16:47
add a comment |Â
1
Depending on the implementation, thesed/awkones may not work for non-text files. Theawkone would add back a missing trailing newline character (sedas well with some implementations, some others would remove the unterminated line)
â Stéphane Chazelas
Feb 1 at 15:48
@StéphaneChazelas Yes. I've changed my wording to be slightly more careful.
â Kusalananda
Feb 1 at 15:52
1
I think what would make your nitpick even better is to say that you can redirect standard streams, or perhaps file descriptors in general. "Output of a program" can be arguably stretched as a term.
â Sergiy Kolodyazhnyy
Feb 1 at 16:47
1
1
Depending on the implementation, the
sed/awk ones may not work for non-text files. The awk one would add back a missing trailing newline character (sed as well with some implementations, some others would remove the unterminated line)â Stéphane Chazelas
Feb 1 at 15:48
Depending on the implementation, the
sed/awk ones may not work for non-text files. The awk one would add back a missing trailing newline character (sed as well with some implementations, some others would remove the unterminated line)â Stéphane Chazelas
Feb 1 at 15:48
@StéphaneChazelas Yes. I've changed my wording to be slightly more careful.
â Kusalananda
Feb 1 at 15:52
@StéphaneChazelas Yes. I've changed my wording to be slightly more careful.
â Kusalananda
Feb 1 at 15:52
1
1
I think what would make your nitpick even better is to say that you can redirect standard streams, or perhaps file descriptors in general. "Output of a program" can be arguably stretched as a term.
â Sergiy Kolodyazhnyy
Feb 1 at 16:47
I think what would make your nitpick even better is to say that you can redirect standard streams, or perhaps file descriptors in general. "Output of a program" can be arguably stretched as a term.
â Sergiy Kolodyazhnyy
Feb 1 at 16:47
add a comment |Â
up vote
0
down vote
simple way is to copy:
cp file1 file2
there are multiple ways to divert the flow of output data into another file as well e.g.:
cat file1 > file2
less file1 > file2
more file1 > file2
You can use rsync to take backup:
rsync -r /media/hdd1/Folder1/ /media/hdd2/Folder2/
rsync is backing up whole folder from one drive to another and -r option specifies to do it recursively for all files and subfolders.
add a comment |Â
up vote
0
down vote
simple way is to copy:
cp file1 file2
there are multiple ways to divert the flow of output data into another file as well e.g.:
cat file1 > file2
less file1 > file2
more file1 > file2
You can use rsync to take backup:
rsync -r /media/hdd1/Folder1/ /media/hdd2/Folder2/
rsync is backing up whole folder from one drive to another and -r option specifies to do it recursively for all files and subfolders.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
simple way is to copy:
cp file1 file2
there are multiple ways to divert the flow of output data into another file as well e.g.:
cat file1 > file2
less file1 > file2
more file1 > file2
You can use rsync to take backup:
rsync -r /media/hdd1/Folder1/ /media/hdd2/Folder2/
rsync is backing up whole folder from one drive to another and -r option specifies to do it recursively for all files and subfolders.
simple way is to copy:
cp file1 file2
there are multiple ways to divert the flow of output data into another file as well e.g.:
cat file1 > file2
less file1 > file2
more file1 > file2
You can use rsync to take backup:
rsync -r /media/hdd1/Folder1/ /media/hdd2/Folder2/
rsync is backing up whole folder from one drive to another and -r option specifies to do it recursively for all files and subfolders.
answered Feb 1 at 16:14
Aqeel Asghar
11
11
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f421219%2fhow-to-redirect-all-the-content-of-one-file-to-another-file%23new-answer', 'question_page');
);
Post as a guest
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
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
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
cat file_a > file_bâ RomanPerekhrest
Feb 1 at 14:53
2
@RomanPerekhrest pleaes make that an answer. Trivial though it is.
â roaima
Feb 1 at 14:53
2
@roaima, I can't: it's too primitive and not imposing ...
â RomanPerekhrest
Feb 1 at 14:54
@roaima It's only "trivial" if you disregard what's going on ;-) (what's opening what file and what's happening to permissions etc. in various cases)
â Kusalananda
Feb 1 at 15:42
@Kusalananda at the level the OP is asking the simple form of the answer is trivial ("How do you get a directory listing? -
ls"), although I accept that if you have zero knowledge nothing is really trivial. I like your answer because it gives a solution at the simplest possible level, but then goes on to explain for other readers some of the extras that might be relelvant.â roaima
Feb 1 at 19:50