Creating a file in Linux? (Touch vs Echo)Why isn't there any shell command to create files?differences...
How could a medieval fortress manage large groups of migrants and travelers?
Why is Katakana not pronounced Katagana?
What is the word for "event executor"?
How to ask my office to remove the pride decorations without appearing anti-LGBTQ?
Unix chat server making communication between terminals possible
How to remove the first colon ':' from a timestamp?
Advice for paying off student loans and auto loans now that I have my first 'real' job
How Can I Process Untrusted Data Sources Securely?
When does Fisher's "go get more data" approach make sense?
Link of a singularity
Manually select/unselect lines before forwarding to stdout
Why does FFmpeg choose 10+20+20 ms instead of an even 16 ms for 60 fps GIF images?
Alphanumeric Line and Curve Counting
What "fuel more powerful than anything the West (had) in stock" put Laika in orbit aboard Sputnik 2?
how many bits in the resultant hash will change, if the x bits are changed in its the original input
Is there a source that says only 1/5th of the Jews will make it past the messiah?
Why did Spider-Man take a detour to Dorset?
How could an animal "smell" carbon monoxide?
Why did Steve Rogers choose this character in Endgame?
Is there any conditions on a finite abelian group so that it cannot be class group of any number field?
What could be reasoning of male prison in VR world to only allow undershirt and sarong as nightwear to male prisoners
Intel 8080-based home computers
Bone Decomposition
Can a Resident Assistant Be Told to Ignore a Lawful Order?
Creating a file in Linux? (Touch vs Echo)
Why isn't there any shell command to create files?differences between echo“”> and > commandFastest way to get list of all file sizesecho string >> file does not workCreation of a WORM fileecho bytes to a fileHow to compare file sizes in two directories?How to list directory/file sizes in general on UNIX-like systems?File size after cutWhen does touch command need the file to exist?How to `touch` and `cat` file named `-`
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I'm pretty new the Linux in general so I'm not too familiar with do's and don'ts or some commands.
I wanted to create a file and noticed that:
touch file.txt `
creates a file but so does:
echo >> file.txt
and also
> file.txt
The files created with ">" and "touch" are both 0 bytes but the file created with "echo" is 1 byte
why are the files different sizes and whats the best way to create a file? when should someone create a file with "echo" instead of "touch" or ">"?
linux ubuntu files echo touch
New contributor
add a comment |
I'm pretty new the Linux in general so I'm not too familiar with do's and don'ts or some commands.
I wanted to create a file and noticed that:
touch file.txt `
creates a file but so does:
echo >> file.txt
and also
> file.txt
The files created with ">" and "touch" are both 0 bytes but the file created with "echo" is 1 byte
why are the files different sizes and whats the best way to create a file? when should someone create a file with "echo" instead of "touch" or ">"?
linux ubuntu files echo touch
New contributor
add a comment |
I'm pretty new the Linux in general so I'm not too familiar with do's and don'ts or some commands.
I wanted to create a file and noticed that:
touch file.txt `
creates a file but so does:
echo >> file.txt
and also
> file.txt
The files created with ">" and "touch" are both 0 bytes but the file created with "echo" is 1 byte
why are the files different sizes and whats the best way to create a file? when should someone create a file with "echo" instead of "touch" or ">"?
linux ubuntu files echo touch
New contributor
I'm pretty new the Linux in general so I'm not too familiar with do's and don'ts or some commands.
I wanted to create a file and noticed that:
touch file.txt `
creates a file but so does:
echo >> file.txt
and also
> file.txt
The files created with ">" and "touch" are both 0 bytes but the file created with "echo" is 1 byte
why are the files different sizes and whats the best way to create a file? when should someone create a file with "echo" instead of "touch" or ">"?
linux ubuntu files echo touch
linux ubuntu files echo touch
New contributor
New contributor
New contributor
asked 1 hour ago
Alex ValdezAlex Valdez
61 bronze badge
61 bronze badge
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
For the general question about creating files, see: Why isn't there any shell command to create files?
With both > file
and echo >> file
, the shell creates the file if it didn't already exist.
With > file
, the file is truncated if it already existed. No command was specified, so nothing gets written to the file and the file will be empty.
echo
, without any arguments, prints an empty line. So the output contains the line ending character, typically linefeed (LF, n
):
% echo | od -c
0000000 n
0000001
So with echo >> file
, you get one byte written to the file. If the file already existed, then it would have one byte added to it, because you used >>
(append) instead of >
(overwrite).
touch
creates a file if it didn't already exist, and updates the timestamps on it otherwise. touch
doesn't change the contents of the file, so if it already existed and had some contents in it, the contents would remain the same after touch
.
Which you want to use depends on what effect you want.
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
});
}
});
Alex Valdez 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%2f530555%2fcreating-a-file-in-linux-touch-vs-echo%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
For the general question about creating files, see: Why isn't there any shell command to create files?
With both > file
and echo >> file
, the shell creates the file if it didn't already exist.
With > file
, the file is truncated if it already existed. No command was specified, so nothing gets written to the file and the file will be empty.
echo
, without any arguments, prints an empty line. So the output contains the line ending character, typically linefeed (LF, n
):
% echo | od -c
0000000 n
0000001
So with echo >> file
, you get one byte written to the file. If the file already existed, then it would have one byte added to it, because you used >>
(append) instead of >
(overwrite).
touch
creates a file if it didn't already exist, and updates the timestamps on it otherwise. touch
doesn't change the contents of the file, so if it already existed and had some contents in it, the contents would remain the same after touch
.
Which you want to use depends on what effect you want.
add a comment |
For the general question about creating files, see: Why isn't there any shell command to create files?
With both > file
and echo >> file
, the shell creates the file if it didn't already exist.
With > file
, the file is truncated if it already existed. No command was specified, so nothing gets written to the file and the file will be empty.
echo
, without any arguments, prints an empty line. So the output contains the line ending character, typically linefeed (LF, n
):
% echo | od -c
0000000 n
0000001
So with echo >> file
, you get one byte written to the file. If the file already existed, then it would have one byte added to it, because you used >>
(append) instead of >
(overwrite).
touch
creates a file if it didn't already exist, and updates the timestamps on it otherwise. touch
doesn't change the contents of the file, so if it already existed and had some contents in it, the contents would remain the same after touch
.
Which you want to use depends on what effect you want.
add a comment |
For the general question about creating files, see: Why isn't there any shell command to create files?
With both > file
and echo >> file
, the shell creates the file if it didn't already exist.
With > file
, the file is truncated if it already existed. No command was specified, so nothing gets written to the file and the file will be empty.
echo
, without any arguments, prints an empty line. So the output contains the line ending character, typically linefeed (LF, n
):
% echo | od -c
0000000 n
0000001
So with echo >> file
, you get one byte written to the file. If the file already existed, then it would have one byte added to it, because you used >>
(append) instead of >
(overwrite).
touch
creates a file if it didn't already exist, and updates the timestamps on it otherwise. touch
doesn't change the contents of the file, so if it already existed and had some contents in it, the contents would remain the same after touch
.
Which you want to use depends on what effect you want.
For the general question about creating files, see: Why isn't there any shell command to create files?
With both > file
and echo >> file
, the shell creates the file if it didn't already exist.
With > file
, the file is truncated if it already existed. No command was specified, so nothing gets written to the file and the file will be empty.
echo
, without any arguments, prints an empty line. So the output contains the line ending character, typically linefeed (LF, n
):
% echo | od -c
0000000 n
0000001
So with echo >> file
, you get one byte written to the file. If the file already existed, then it would have one byte added to it, because you used >>
(append) instead of >
(overwrite).
touch
creates a file if it didn't already exist, and updates the timestamps on it otherwise. touch
doesn't change the contents of the file, so if it already existed and had some contents in it, the contents would remain the same after touch
.
Which you want to use depends on what effect you want.
answered 59 mins ago
murumuru
41.7k5 gold badges101 silver badges175 bronze badges
41.7k5 gold badges101 silver badges175 bronze badges
add a comment |
add a comment |
Alex Valdez is a new contributor. Be nice, and check out our Code of Conduct.
Alex Valdez is a new contributor. Be nice, and check out our Code of Conduct.
Alex Valdez is a new contributor. Be nice, and check out our Code of Conduct.
Alex Valdez 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%2f530555%2fcreating-a-file-in-linux-touch-vs-echo%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